Embedded Jetty Server - no JSP support for /, org.apache.jasper.servlet.JspServlet not found

I have the following code to use the embedded Jetty server next to a simple servlet and a .jsp webpage. However, after compiling and running the code:

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 

I get an error message:

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

And going to /index.jsp results in a 500 error.

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

I read this post , but I don’t think the solution is applied here because I am running Jetty and not using start.jar.

How can I resolve this error so that the server is up and running .jsp pages successfully?

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. \n\n"); 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> 

This is my project structure:

 webapp ----com ----test ----MyServlet.java ----ServerMain.java ----index.jsp ----web.xml ----lib ----jetty-all.jar ----servlet-api.jar 
+5
source share
3 answers

It seems that you are missing a JAR file that includes the org.apache.jasper.servlet.JspServlet class. Download the JAR file containing it (see here ) and add it to your class path. In addition, on a side note, you should replace com/test/ServerMain with the name of the real class, com.test.ServerMain . You should look like this:

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

By the way, there is a github project supported by the Jetty Project, demonstrating JSP support in Jetty Embedded.

https://github.com/jetty-project/embedded-jetty-jsp

+2
source

They didn’t try to deploy Jetty, but when starting Jetty 9.3 as a service, you need to add JSP support.

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

Where JETTY_BASE is your folder in which you deploy the application that is separate from JETTY_HOME . Therefore, I assume that the built-in Jetty will need a similar configuration.

+2
source

Source: https://habr.com/ru/post/1204105/


All Articles