Http error 500 jsp support not configured

I currently have Jetty embedded into an application. The Jetty server starts up and I can see the files in the project, however when I try to view a JSP file it says HTTP ERROR 500Problem acces...

I currently have Jetty embedded into an application. The Jetty server starts up and I can see the files in the project, however when I try to view a JSP file it says

HTTP ERROR 500
Problem accessing /web/index.jsp. Reason:
JSP support not configured

I have read some other posts on here and some tutorials online and most of them talk about start.jar and maven. I’m not using either of those I’m just using what is built into eclipse.

I have three classes

AppContextBuilder

public class AppContextBuilder
{

private WebAppContext webAppContext;


public WebAppContext buildWebAppContext()
{
    webAppContext = new WebAppContext();
    webAppContext.setDescriptor( webAppContext + "/WEB-INF/web.xml" );
    webAppContext.setResourceBase( "." );
    webAppContext.setContextPath( "/" );
    return webAppContext;
}

JettyServer

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

public class JettyServer
{

private Server server;


public JettyServer()
{
    this( 8585 );
}


public JettyServer(Integer runningPort)
{
    server = new Server( runningPort );
}


public void setHandler( ContextHandlerCollection contexts )
{
    server.setHandler( contexts );
}


public void start() throws Exception
{
    server.start();
}


public void stop() throws Exception
{
    server.stop();
    server.join();
}


public boolean isStarted()
{
    return server.isStarted();
}


public boolean isStopped()
{
    return server.isStopped();
}
}

ServerControl

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

public class ServerControl
{

public static void main( String[] args )
{
    Logger.getLogger().logMethodEntryMessage();

    ContextHandlerCollection contexts = new ContextHandlerCollection();

    contexts.setHandlers( new Handler[]
    { new AppContextBuilder().buildWebAppContext() } );

    final JettyServer jettyServer = new JettyServer();
    jettyServer.setHandler( contexts );

    start( jettyServer );

    Logger.getLogger().logMethodExitMessage();        
}


private static void start( final JettyServer jettyServer )
{
    Logger.getLogger().logMethodEntryMessage();

    try
    {
        jettyServer.start();
        Logger.getLogger().debug( "Jetty server started!" );
    }
    catch( Exception e )
    {
        Logger.getLogger().error( e.getMessage() );
    }

    Logger.getLogger().logMethodExitMessage();
}

}

I’ve never tried to use jetty embedded before so I may be missing something. I followed this tutorial online though and it seems to work for them.

Any help would be great, thanks!

Contents

  • 1 Big Problems
    • 1.1 What about locked files on Windows?
    • 1.2 Why isn’t my application/servlet/content served?
    • 1.3 Jetty has locked up?
    • 1.4 JSP support not configured?
    • 1.5 Why does StressTest.java fail on Mac OS?
  • 2 Logs and Warnings
    • 2.1 Why do I get JVM Bugs reported?
    • 2.2 Why do I get a «Save could not be completed» error in Eclipse whenever I try to save a file while Jetty is running?

Big Problems

Question Mark.png What about locked files on Windows?

Question Mark.png Why isn’t my application/servlet/content served?

To diagnose the problem:

  • If you think your application is running, but you get a 404 response, make sure that you have correctly set the context path.
  • If you click a link to access the application, make sure you don’t have a relative URL problem. Remember that a link to foo/bar on a page at /myapp/page goes to /myapp/foo/bar. If you want it to go to /myapp/page/foo/bar, make sure the browser is redirected from /myapp/page to /myapp/page/.
  • If you still cannot get your content, look in the requestlog to see the exact URL that is being requested.
  • If you receive a 503 Unavailable response, an exception occurred while deploying the web application. Check the log for details.

Question Mark.png Jetty has locked up?

If your requests are not getting any responses, a frequent description of the problem is that «Jetty locked up.» To diagnose such problems, it is very important to work out exactly what has locked up.

  • You can test whether the JVM has locked up completely by trying to use a tool like Jconsole or jvisualvm to attach to the process.
    • If you cannot attach to the process, it is likely something has gone wrong with the JVM and/or the operating system rather than Jetty itself.
    • If you can attach to the JVM with Jconsole and/or jvisualvm, look to see how many threads are allocated and what tasks they are doing. A frequent cause of lockups is a slow database so that all the threads in the thread pool end up waiting for a JDBC connection from the connection pool.
  • You can test whether Jetty is completely locked up by trying some simple requests to see if they get a response. Opening http://thehost.com/favicon.icon or some other image directly is often a good way to see if Jetty is still running. If it is, try some simple requests within the application that use minimal features (no authentication, no database, for example) and see if any of those requests work.
  • Finally, you can use telnet as a fake HTTP client to see if Jetty is accepting connections. If you telnet to the port (80 or 8080) and you see a «Connected to www.example.com» message, Jetty is still accepting connections. Next try typing a request like «OPTION * HTTP/1.0» and press Enter twice to see if you get an HTTP response:
   # telnet blogs.webtide.com 80
   Trying 72.32.76.94...
   Connected to blogs.webtide.com.
   Escape character is '^]'.
   OPTION * HTTP/1.0
   HTTP/1.1 503 Service Unavailable
   Cache-Control: must-revalidate,no-cache,no-store
   Content-Type: text/html;charset=ISO-8859-1
   Content-Length: 1287
   Server: Jetty(7.0.0.v20091005)
   

Check that the Server in the response field is Jetty (and not a load balancer, etc.).

Doing tests like these helps narrow down exactly which component has locked up. Getting a thread dump (with jstack or ctl- or jvisualvm) is also invaluable to diagnose what the threads are doing.

Question Mark.png JSP support not configured?

JSP is an option for Jetty. You must specify the JSP option for the start.jar command line. (As of Jetty 7.1.x, the jetty@eclipse download includes the JSP Jars.)

If JSP is incorrectly configured, each context started produces an error message like:

INFO::NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet

A request to a JSP generates a 500 response with the message «500 JSP support not configured»

Question Mark.png Why does StressTest.java fail on Mac OS?

StressTest in jetty-server might fail on Mac OS X due to an insufficient port range. Most operating systems have a limit of 65535 available TCP/IP ports.

Read the following wikipedia entry for details:

http://en.wikipedia.org/wiki/Ephemeral_port

[…]The IANA suggests 49152 to 65535 as «dynamic and/or private ports.[…]

[…]Many Linux kernels use 32768 to 61000.[…]

We have fixed the test code to make it run successfully on Mac OS. If it nonetheless fails on your Mac OS, raise the port range by executing the following two commands in a terminal:

sudo sysctl -w net.inet.ip.portrange.first=32768
sudo sysctl -w net.inet.ip.portrange.hifirst=32768

It seems that Apple raised the limits for Mac OS Lion, so on Lion it should work from scratch. If not, apply the

sysctl

commands and retry.

Logs and Warnings

Question Mark.png Why do I get JVM Bugs reported?

Yes!
There are several NIO bugs in the JVM (especially for Linux) that are not fixed in the 1.6.x series. Jetty has implemented a number of JVM NIO Bug work arounds that keep a Jetty server working efficiently in the presence of these problems.

Question Mark.png Why do I get a «Save could not be completed» error in Eclipse whenever I try to save a file while Jetty is running?

This is a limitation of Windows — having a file open in one process means that you can’t write to that same file with another process. Since Jetty has mapped the file to its cache, which prevents the file from being edited, you need to turn off caching to work around the problem. You can turn off caching in the default servlet by setting <useFileMappedBuffer> to false in webdefault.xml.

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. Jetty – JSP Support Not Configured Example

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

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:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javacodegeeks.example</groupId>
  <artifactId>jettyjspconfiguration-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
    <dependencies>	        
	        <dependency>
	            <groupId>org.eclipse.jetty</groupId>
	            <artifactId>jetty-server</artifactId>
	            <version>9.2.15.v20160210</version>
	        </dependency>
	        <dependency>
	            <groupId>org.eclipse.jetty</groupId>
	            <artifactId>jetty-annotations</artifactId>
	            <version>9.2.15.v20160210</version>
	        </dependency>
	        <dependency>
	            <groupId>org.eclipse.jetty</groupId>
	            <artifactId>jetty-webapp</artifactId>
	            <version>9.2.15.v20160210</version>
	        </dependency>
</dependencies> 
</project>

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:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5">
	<display-name>Jetty JSP Configuration Example</display-name>
</web-app>

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:

 
<html>
<head>
<title>Sample JSP Page</title>
<meta>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
</meta>
</head>

<body>
	<c:out value="Jetty JSP Configuration Example"></c:out>
	<br /> 
	<% System.out.println("Hello Java Code Geeks"); %>
	<div align="center" style="margin-top: 50px;">
 
        <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>
</body>
</html>

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

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&gtjstl</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$");
  1. org.eclipse.jetty.webapp.FragmentConfiguration processes all WEB-INF/web-fragment.xml files.
  2. 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.
  3. org.eclipse.jetty.plus.webapp.PlusConfiguration will support JNDI aspects of WEB-INF/web.xml.
  4. We will use org.eclipse.jetty.annotations.AnnotationConfiguration to scan container and webapp jars looking for annotations related to WebServlet, WebFilter or WebListener.
  5. 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

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:

  1. Configuring JSP
  2. Embedded Jetty
  3. Jetty-JSP-Example

У меня есть следующий код для использования встроенного сервера Jetty рядом с простым сервлетом и веб-страницей .jsp. Однако после компиляции и запуска кода:

javac -cp lib/servlet-api.jar:lib/jetty-all.jar com/test/MyServlet.java 
javac -cp lib/servlet-api.jar:lib/jetty-all.jar com/test/ServerMain.java 
java -cp .:lib/servlet-api.jar:lib/jetty-all.jar com/test/ServerMain

Я получаю сообщение об ошибке:

INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet

И переход к /index.jsp приводит к ошибке 500.

HTTP ERROR 500
Problem accessing /index.jsp. 
Reason:
JSP support not configured

Я прочитал этот пост, но я не думаю, что решение применяется здесь, потому что я запускаю Jetty, а не используя start.jar.

Как я могу разрешить эту ошибку, чтобы сервер работал и успешно обслуживал страницы .jsp?

ServerMain.java

package com.test;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class ServerMain {

    public static void main(String[] args) throws InterruptedException {

        Server server = new Server(8080);
        WebAppContext webApp = new WebAppContext();
        webApp.setDescriptor("web.xml");
        webApp.setResourceBase("");
        webApp.setParentLoaderPriority(true);
        server.setHandler(webApp);

        try {
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
        server.join();
    }
}

MyServlet.java

package com.test;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, this is a testing servlet. nn");
        Properties p = System.getProperties();
        p.list(resp.getWriter());

    }
}

web.xml

   <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC "-//Oracle Corporation//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.test.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Это моя структура проекта:

webapp
----com
    ----test
        ----MyServlet.java
        ----ServerMain.java
        ----index.jsp
        ----web.xml
----lib
    ----jetty-all.jar
    ----servlet-api.jar  

Вопрос:

У меня есть следующий код для использования встроенного сервера Jetty рядом с простым сервлетом и веб-страницей .jsp. Однако после компиляции и запуска кода:

javac -cp lib/servlet-api.jar:lib/jetty-all.jar com/test/MyServlet.java
javac -cp lib/servlet-api.jar:lib/jetty-all.jar com/test/ServerMain.java
java -cp .:lib/servlet-api.jar:lib/jetty-all.jar com/test/ServerMain

Я получаю сообщение об ошибке:

INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet

И переход к /index.jsp приводит к ошибке 500.

HTTP ERROR 500
Problem accessing /index.jsp.
Reason:
JSP support not configured

Я прочитал этот пост, но я не думаю, что решение применяется здесь, потому что я запускаю Jetty, а не используя start.jar.

Как я могу разрешить эту ошибку, чтобы сервер работал и успешно обслуживал страницы .jsp?

ServerMain.java

package com.test;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class ServerMain {

public static void main(String[] args) throws InterruptedException {

Server server = new Server(8080);
WebAppContext webApp = new WebAppContext();
webApp.setDescriptor("web.xml");
webApp.setResourceBase("");
webApp.setParentLoaderPriority(true);
server.setHandler(webApp);

try {
server.start();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
server.join();
}
}

MyServlet.java

package com.test;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

resp.setContentType("text/plain");
resp.getWriter().println("Hello, this is a testing servlet. nn");
Properties p = System.getProperties();
p.list(resp.getWriter());

}
}

web.xml

   <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC "-//Oracle Corporation//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.test.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Это моя структура проекта:

webapp
----com
----test
----MyServlet.java
----ServerMain.java
----index.jsp
----web.xml
----lib
----jetty-all.jar
----servlet-api.jar

Лучший ответ:

Кажется, что вам не хватает JAR файла, который включает класс org.apache.jasper.servlet.JspServlet. Загрузите файл JAR, содержащий его (посмотрите здесь) и добавьте его в свой путь к классам. Кроме того, на боковой ноте вы должны заменить com/test/ServerMain на имя реального класса, com.test.ServerMain. Вы должны выглядеть так:

java -cp ".:lib/servlet-api.jar:lib/jetty-all.jar:lib/apache-jasper.jar" com.test.ServerMain

Ответ №1

Ответ №2

Не пытались внедрить Jetty, но при запуске Jetty 9.3 в качестве службы вам нужно добавить поддержку JSP.

cd $JETTY_BASE
$JAVA_HOME/bin/java -jar $JETTY_HOME/start.jar --add-to-startd=jsp

Где JETTY_BASE – это ваша папка, в которой вы развертываете приложение, которое отделено от JETTY_HOME. Поэтому я предполагаю, что встроенный Jetty будет нуждаться в подобной конфигурации.

Понравилась статья? Поделить с друзьями:
  • Http error 500 htaccess
  • Http error 500 google chrome
  • Http error 429 too many requests python
  • Http error 500 exchange 2016
  • Http error 429 instagram vpn