Jetty “JSP Support not Configured” Error (original) (raw)
In this example, we will show how to resolve an error which is frequently encountered if you are using Java Server Pages (JSP). Java Server Pages is a server side technology and it is used to create dynamic java web application. JSP can be considered an extension to servlet technology. We will use embedded jetty to show the error and how to resolve error JSP Support not configured
. If you want to learn more about how to use standalone jetty to deploy servlets, you can read here
1. Environment
In this example, we will use following environment:
- Eclipse Kepler 4.3
- Jetty Version 9.2.15
- Java version 7
- Java Servlet library – servlet-api-3.1
- Maven 3.0.4
2.1 Outline of example
In this example we will create a maven project with an embedded jetty. We will write a JSP page which will run on embedded jetty. We will show the error JSP Not Configured
and then we will show how to resolve this error by configuring JSP in embedded jetty. At the end, we will also discuss why standalone jetty was not used for this example and show what ways we can configure JSP in standalone jetty.
2.2 Create a Maven Project
Here are the steps to create a Maven Project in eclipse:
2.2.1. Create a new Maven project
As shown in below screenshot, create a new maven project. Fill in the detail with GroupId as com.javacodegeeks.example
and ArtifactId as jettyjspconfiguration-example
New Maven Project
2.2.2 Modify pom.xml file
POM is a Project Object Model and it is an xml file in Maven project. The file contains the information related to project and configuration details used by Maven to build the project. We will add some dependencies like jetty server
, jetty-webapp
and jetty-annotations
. These dependencies are needed to run our web application on embedded jetty server. Once we have added these dependencies, our pom.xml file will look like as shown below:
2.2.3 Configure Web Application
Create a WEB-INF folder under src/main/webapp
and add web.xml
file. The content of the file will be like below:
Jetty JSP Configuration Example
2.2.4 Simple JSP Application
Now we will write a simple JSP web page and Java code to run our embedded jetty server. Create a file index.jsp in eclipse project under project-name-> src -> main -> webapp. This is a simple JSP web page to print Hello Java Code Geeks
. Our index.jsp will look like below:
<% System.out.println("Hello Java Code Geeks"); %>
<form id="loginForm">
Please enter your Username: <input type="text" name="username" size="20px"> <br>
Please enter your Password: <input type="text" name="password" size="20px"> <br><br>
<input type="submit" value="submit">
</form>
</div>
We will write our java code to run jetty server. Let’s create java source file JettyJSPConfiguration.java
under src->main->java as shown below:
package com.javacodegeeks.example;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext;
public class JettyJSPConfiguration {
public static void main(String[] args) {
Server server = new Server(8580);
WebAppContext ctx = new WebAppContext();
ctx.setResourceBase("src/main/webapp");
ctx.setContextPath("/jettyjspconfiguration-example");
server.setHandler(ctx);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.2.5 Run our example
Now once we run JettyJSPConfiguration.java
from eclipse, we can access the web application in browser at port 8580. Once the server is started, let’s go to browser and access http://localhost:8580/jettyjspconfiguration-example/index.jsp
and we will get below error
Jetty JSP Support Not Configured Error
3. How to configure JSP Support
To fix our error Jetty JSP Support Not Configured
, we will configure JSP support in our embedded jetty server. In our pom.xml, we will add apache-jsp dependency to handle JSP along with jstl dependency to handle JSP tag library. This will look like below:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp/<artifactId>
<version>9.2.15.v20160210</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
We will do following changes in our Java source code to support JSP configuration for an embedded jetty. We will need to include jstl jar in building our application, so compiler can recognize jsp tags.
ctx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*jstl.*\.jar$");
org.eclipse.jetty.webapp.FragmentConfiguration
processes all WEB-INF/web-fragment.xml files.- We can extend the support of container by adding some extra configurations which will be needed to deploy a webapp.
org.eclipse.jetty.plus.webapp.EnvConfiguration
is used to create environment for webapp which is applied through WEB-INF/jetty-env.xml in a standalone jetty. org.eclipse.jetty.plus.webapp.PlusConfiguration
will support JNDI aspects of WEB-INF/web.xml.- We will use
org.eclipse.jetty.annotations.AnnotationConfiguration
to scan container and webapp jars looking for annotations related to WebServlet, WebFilter or WebListener. org.eclipse.jetty.webapp.JettyWebXmlConfiguration
is used to look for xml configuration in WEB-INF.
It is important to note how these configurations are added in server classlist. This is how we will add those configurations through code:
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
4. Run the web application
Once we are done with changes to java source code, we can run our project from eclipse and it will start our embedded jetty server. We will see the output of our JSP file in browser and also Hello Java Code Geeks
in console of eclipse.
jetty jsp configuration example output
5. Standalone Jetty Server
If you are using jetty version 9.2.15 v20160210, jsp is by default enabled. In $jetty.base/start.d/jsp.ini
file has following settings to enable jsp --module=jsp
and jsp-impl=apache
6. Conclusion
In this example, we showed how to resolve the error jetty JSP support not configured
by configuring jsp for embedded-jetty server.
7. Download the eclipse project
This was an example to configure JSP on an embedded-jetty.
8. Related Articles
Following articles were referred in developing this example:
Yogesh currently lives in Minneapolis and works as a Senior Software Engineer. He has a masters degree in Computer Science from University of Minnesota, Twin Cities. At graduate school, he did research in programming languages because of his love for functional and object oriented programming. Currently he delves into more details of Java, web development and security. Previously he worked as a product manager to create web application for health insurance brokers. In his free time, he listens to music and writes fictional stories.