1、所需的jar包(jsp2.1):
- servlet-api-2.5-6.x.jar
- jetty-util-6.x.jar
- jetty-6.x.jar
- ant-1.6.5.jar
- core-3.1.1.jar
- jsp-2.1.jar
- jsp-api-2.1.jar
2、示例代码片段:
//设置web根目录
String rootDirectory = System.getProperty("user.dir");
Context context = new WebAppContext(contexts, rootDirectory+"/webapp","/");
context.setWelcomeFiles(new String[]{"index.jsp"});
//端口监听
int port = 80;
Server server = new Server();
Connector httpConnector = new SelectChannelConnector();
httpConnector.setHost(null);
httpConnector.setPort(port);
server.addConnector(httpConnector);
//设置Handler
server.setHandlers(new Handler[] { contexts, new DefaultHandler() });
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(HttpDemoServlet.class, "/");
ContextHandler contextHandler = new ContextHandler(contexts, "/httpdemo");
contextHandler.setHandler(handler);
try {
//启动服务.
server.start();
}
catch (Exception e) {
e.printStackTrace();
}
posted on 2008-01-03 14:03
josson 阅读(359)
评论(0) 编辑 收藏 所属分类:
java 开发