更新时间:2023-12-04 14:49:46
这个问题经常出现,所以我创建了一个使用嵌入式Jetty并启用JSP的示例项目。
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/
加载此项投射到你最喜欢的IDE。
Load up this project into your favorite IDE.
运行 org.eclipse.jetty.demo.Main
类,然后使用你的浏览器并打开 http:// localhost:8080 /
Run the org.eclipse.jetty.demo.Main
class and then use your browser and open http://localhost:8080/
快速浏览
src / main / java / org / eclipse / jetty / demo / Main.java
包含创建/配置/启动嵌入式服务器的部分。
src/main/java/org/eclipse/jetty/demo/Main.java
contains the part that creates / configures / and starts the embedded server.
特别注意:
jspServletHolder()
org.eclipse.jetty.containerInitializers
需要为JSP初始化程序设置 ServletContainerInitializersStarter
bean InstanceManager
引用 javax.servlet.context.tempdir
需要创建 org.apache.jasper.compiler.disablejsr199
设置为 false
使用标准JavaC编译器 getUrlClassLoader()
defaultServletHolder()
jspServletHolder()
org.eclipse.jetty.containerInitializers
needs to be setup for the JSP initializersServletContainerInitializersStarter
bean needs to be addedInstanceManager
reference needs to be addedjavax.servlet.context.tempdir
needs to be createdorg.apache.jasper.compiler.disablejsr199
to false
to use the standard JavaC compilergetUrlClassLoader()
defaultServletHolder()
src / main / java / com / acme / DateServlet.java
是如何从Servlet转发到JSP的示例。
src/main/java/com/acme/DateServlet.java
is an example of how to forward to a JSP from a Servlet.
DateServlet是映射到 / date /
The DateServlet is mapped to path spec of /date/
in Main.java
所以一旦你点击 http:// localhost:8080 / date /
请求将命中servlet,而servlet又转发到 /test/tag2.jsp
So once you hit http://localhost:8080/date/
the request will hit the servlet, which in turn forwards to to /test/tag2.jsp