jdk17内嵌jetty11,配置jsp界面
时间: 2023-08-24 09:07:05 浏览: 45
我理解您的问题是如何在JDK17中内嵌Jetty11并配置JSP界面。首先,需要在项目中添加Jetty11的依赖,例如Maven项目可以在pom.xml文件中添加以下依赖:
```xml
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>11.0.6</version>
</dependency>
```
然后,在代码中启动Jetty11并配置JSP界面,可以参考以下示例代码:
```java
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class EmbeddedJetty {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setResourceBase("src/main/webapp");
webapp.setClassLoader(Thread.currentThread().getContextClassLoader());
webapp.setConfigurationClasses(new String[]{"org.eclipse.jetty.webapp.WebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration"});
webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*jstl.*\\.jar$");
webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*taglibs.*\\.jar$");
webapp.setDescriptor("src/main/webapp/WEB-INF/web.xml");
webapp.setParentLoaderPriority(true);
server.setHandler(webapp);
server.start();
server.join();
}
}
```
此代码将在8080端口启动Jetty11并将Web应用程序部署在src/main/webapp目录下。在此目录下,您可以创建一个JSP文件并通过http://localhost:8080/访问它。