import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; public class EmbeddingJettyWithServlet { public static void main(String[] args) throws Exception { Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/hello");
server.setHandler(context); context.addServlet(new ServletHolder(new HelloServlet()), "/*");
server.start(); } public static class HelloServlet extends HttpServlet { private static final long serialVersionUID = -6154475799000019575L; private static final String greeting = "Hello World"; protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException { response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(greeting);
} } }

访问URL:http://myhost:8080/hello/

输出:Hello World

上面的程序需要导入servlet-api.jar和jetty-all.jar,jetty的下载地址可以参照:http://www.eclipse.org/jetty/[][]

【Servlet】使用org.eclipse.jetty实现小型的Servlet服务器的更多相关文章

  1. 使用Spring Boot操作Hive JDBC时,启动时报出错误:NoSuchMethodError: org.eclipse.jetty.servlet.ServletMapping.setDef

    使用Spring Boot操作Hive JDBC时,启动时报出错误:NoSuchMethodError: org.eclipse.jetty.servlet.ServletMapping.setDef ...

  2. Jetty启动报错排查org.eclipse.jetty.util.MultiException: Multiple exceptions

    最近自己搭建了一个spring的项目,使用Maven做项目构建,使用JDK8,为了方便启动就使用jetty作为启动容器,但是却无意间步入了一个坑 [WARNING] Failed startup of ...

  3. maven eclipse jetty debug

    可以通过查看最近版本: http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server http://search.maven.org ...

  4. java.lang.ClassNotFoundException: org.eclipse.jetty.plus.webapp.EnvConfiguration

    最近刚接触jetty,在myeclipse8.6中加入了一个项目,运行时就出了这个java.lang.ClassNotFoundException: org.eclipse.jetty.plus.we ...

  5. eclipse jetty启动内存溢出

    一.eclipse jetty启动内存溢出, 异常信息 Exception in thread "ConfigClientWorker-Default" java.lang.Out ...

  6. 【转】Eclipse中创建并运行Servlet项目

    最近看了写http协议的学习资料,因此想要实现下andriod平台和服务器通信,那就servlet吧,哎哟,还不错哦!顺便说下,我这个servlet服务是想获得用户名和密码进行校验,然后反给客户端状态 ...

  7. Eclipse Jetty插件安装

    Eclipse Jetty插件安装 使用方法一: 本地资源包插件下载地址:http://pan.baidu.com/s/1sjNP5Id 或者是地址:http://pan.baidu.com/s/1b ...

  8. org/eclipse/jetty/server/Handler : Unsupported major.minor version 52.0

    注:本文来源于<org/eclipse/jetty/server/Handler : Unsupported major.minor version 52.0> Exception in ...

  9. JFinal启动报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Connector

    - 错误: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/ ...

随机推荐

  1. Log4net的不能产生Log文件的问题

    [问题] 用如下的步骤应用了Log4Net: 建立了一个公用的项目, 在里面引入了Log4net的Nuget package. 在公用的项目中建立了一个类,加上了Log4net的attribute. ...

  2. sublime同步文件与siderbar

    有时候,打开了sider bar,想和Eclipse.idea一样,每打开一个tab,就可以在左侧的sider bar 目录上面看到我当前的位置,于是找到了一个插件. SyncedSideBar 安装 ...

  3. [R]Kick start

  4. powerdesigner 不显示表字段只显示表名

    在空白的地方右键选择 Display Preferences然后在左边的General Settings里选Table然后把Columns 的All Columns勾上 如果能帮上您,请选为满意答案, ...

  5. Your account already has a signing certificate for this machine but it is not present in your keycha

    转载自:https://blog.csdn.net/csdn2314/article/details/73124117 Your account already has a signing certi ...

  6. javascript链式语法

    因为 jQuery 库的缘故,链式语法在前端界变得非常流行.实际上这是一种非常容易实现的模式.基本上,你只需要让每个函数返回 'this',这样其他函数就可以立即被调用.看看下面的例子. var bi ...

  7. C# Directory.GetFiles()获取多个类型格式的文件

    第一种方式 System.IO.Directory.GetFiles()获取多个类型格式的文件 System.IO.Directory.GetFiles("c:\","( ...

  8. 浅谈关于QT中Webkit内核浏览器

    关于QT中Webkit内核浏览器是本文要介绍的内容,主要是来学习QT中webkit中浏览器的使用.提起WebKit,大家自然而然地想到浏览器.作为浏览器内部的主要构件,WebKit的主要工作是渲染.给 ...

  9. web.xml关于spring的讲解

    <context-param>的作用: web.xml的配置中<context-param>配置作用 . 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件w ...

  10. 理解CPU steal time

    http://melody-dc.com/2015/11/21/%E7%90%86%E8%A7%A3CPU-steal-time/ http://www.cnblogs.com/yjf512/p/33 ...