jetty servlet容器(转自博客园)
来源:互联网 发布:自学程序员的步骤 编辑:程序博客网 时间:2024/05/21 10:46
核心类:org.mortbay.jetty.Server
核心接口:org.mortbay.component.LifeCycle
核心线程池封装:org.mortbay.thread.QueuedThreadPool
核心IO处理类:org.mortbay.jetty.nio.SelectChannelConnector
核心Servlet处理类:org.mortbay.jetty.servlet.ServletHandler
代码示例:
private static final long serialVersionUID = 1L;
private String msg = "Hello World!";
public HelloServlet() {
}
public HelloServlet(String msg) {
this.msg = msg;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>" + msg + "</h1>");
response.getWriter().println("session=" + request.getSession(true).getId());
}
}
public class GoodLuckServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
private String msg = "祝你好运!";
public GoodLuckServlet() { public class JettyService {
public static void main(String[] args) throws Exception{
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
// http://localhost:8080/hello
context.addServlet(new ServletHolder(new HelloServlet()), "/hello");
// http://localhost:8080/hello/kongxx
context.addServlet(new ServletHolder(new HelloServlet("Hello Kongxx!")), "/hello/kongxx");
// http://localhost:8080/goodbye
context.addServlet(new ServletHolder(new GoodLuckServlet()), "/goodluck");
// http://localhost:8080/goodbye/kongxx
context.addServlet(new ServletHolder(new GoodLuckServlet("goodluck boy!")), "/goodluck/boy");
server.start();
server.join();
}
}
}
public GoodLuckServlet(String msg) {
this.msg = msg;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>" + msg + "</h1>");
response.getWriter().println("session=" + request.getSession(true).getId());
}
}
- jetty servlet容器(转自博客园)
- 【转】传说最快最轻的Servlet容器Jetty
- Google App Servlet容器转型Jetty
- Jetty之servlet容器(2011.11.09)
- Servlet容器:Jetty和tomcat的比较
- Jetty一个开源的servlet容器
- Servlet容器之Jetty的安装和配置(Windows)
- Servlet容器之Jetty的安装和配置(Windows)
- Java使用Jetty实现嵌入式Web服务器及Servlet容器
- main app方式启动servlet容器(Jetty) 测试web程序
- Java使用Jetty实现嵌入式Web服务器及Servlet容器
- servlet容器tomcat和jetty的简单使用
- Java使用Jetty实现嵌入式Web服务器及Servlet容器
- Resin与其他容器(tomcat/jetty)默认处理Servlet
- 在IDEA中使用maven-jetty-plugin作为servlet容器
- Java使用Jetty实现嵌入式的Servlet容器
- springboot框架servlet容器tomcat、Jetty、undertow压测报告
- Jetty容器
- Qt 信号-槽的同步与异步处理
- Loss Function的修改启发
- zabbix自动发现network
- 利用插件扩展Qt应用程序
- CODE[VS]1010 过河卒
- jetty servlet容器(转自博客园)
- idea maven项目找不到 mapper.xml sql映射文件问题
- 注释必备
- 如何在Windows下安装numpy?
- tomcat启动报错
- .Net 中关于序列化和反序列化Json的方法
- 分析Hive表和分区的统计信息(Statistics)
- JSP的文件上传方法
- 获取表单提交的信息