Jetty: Servlet can't forward to JSP

前端 未结 1 1863
陌清茗
陌清茗 2021-01-16 04:51

I have the following problem: I\'m trying to forward the request from the servlet to the jsp page, but I get an 404. When I´m accessing /sites/home.jsp directly, it loads th

1条回答
  •  迷失自我
    2021-01-16 05:33

    This question comes up often enough, so I created an example project of using Embedded Jetty with JSP enabled.

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

    Load up this project into your favorite IDE.

    Run the org.eclipse.jetty.demo.Main class and then use your browser and open http://localhost:8080/

    Quick Tour

    src/main/java/org/eclipse/jetty/demo/Main.java contains the part that creates / configures / and starts the embedded server.

    Pay particular attention to:

    • The JspServlet must be named "jsp" - see jspServletHolder()
    • The org.eclipse.jetty.containerInitializers needs to be setup for the JSP initializers
    • The ServletContainerInitializersStarter bean needs to be added
    • The InstanceManager reference needs to be added
    • A proper javax.servlet.context.tempdir needs to be created
    • Set org.apache.jasper.compiler.disablejsr199 to false to use the standard JavaC compiler
    • The Classloader for the Context must not be a System Classloader. - see getUrlClassLoader()
    • The DefaultServlet must be named "default" - see defaultServletHolder()

    src/main/java/com/acme/DateServlet.java is an example of how to forward to a JSP from a Servlet.

    The DateServlet is mapped to path spec of /date/ in Main.java

    So once you hit http://localhost:8080/date/ the request will hit the servlet, which in turn forwards to to /test/tag2.jsp

    0 讨论(0)
提交回复
热议问题