心血来潮,决定使用Jetty来做为新的web容器.因而到网上http://download.eclipse.org/jetty/下载了Jetty7,因为8/9两个版本都支持Servlet3.0规范了.而如今绝大多数生产环境的Websphere都仍是采用7系列,即Servlet2.5规范.因此我只下载了Jetty7. java
建立环境,使用eclipse新建一个动态Web工程.注意在勾选的时候不要选择目标容器,由于我这里要使用的是嵌入的方式启动.如图所示: web
将Jetty7自带的jar包都引用到工程中,这里要特别注意把lib/jsp/子包下面的jar也要引用进来,不然不会编译.jsp文件.如图所示: 浏览器
编写启动类: 服务器
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; public class JettyStarter { public static void main(String[] args) throws Exception { // 服务器的监听端口 Server server = new Server(8080); // 关联一个已经存在的上下文 WebAppContext context = new WebAppContext(); // 设置描述符位置 context.setDescriptor("./WebContent/WEB-INF/web.xml"); // 设置Web内容上下文路径 context.setResourceBase("./WebContent"); // 设置上下文路径 context.setContextPath("/jetty"); context.setParentLoaderPriority(true); server.setHandler(context); // 启动 server.start(); server.join(); } }在/WebContent/目录下,建立一个默认的jsp页面
而后启动这个启动器,访问浏览器如图: app