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. Android 从 Android 本地图库选择多个图片

    原文地址 本文说明如何从 Android 本地图库选择多个图片.作者考虑很多解决方案. 演示从 Android 本地图库选择多个图片,有两个方法可以实现从图库中选择多个图片: 用 Intent 获取多 ...

  2. 什么是Session分布式共享

    在了解session分布式共享之前先来了解Session.Redis和Nginx的相关知识. 一.Session相关知识 1.Session 介绍 Session在网络应用中,称为“会话控制”. 每个 ...

  3. javascript将算法复杂度从O(n^2)做到O(n)

    compare the difference of two giving array, return results: 1. elements in both array, 2. elements o ...

  4. nginx做负载均衡,验证码总是不对(2台服务器)

    问题原因:页面中有错误链接,导致跳转到另一台服务器,验证码显示的确是刚开始访问的 (有的静态文件一边没有,就需要去另外一边找,然后就跳了.) 解决方法:把静态文件都提取到了nginx上就解决了.

  5. python中string和十六进制、二进制互转

    def str_to_hex(s): return ' '.join([hex(ord(c)).replace('0x', '') for c in s]) def hex_to_str(s): re ...

  6. 八叉树(Octree)

    八叉树(Octree)是一种用于描述三维空间的树状数据结构.想象一个立方体,我们最少可以切成多少个相同等分的小立方体?答案就是8个.再想象我们有一个房间,房间里某个角落藏着一枚金币,我们想很快的把金币 ...

  7. 如何查看2to3.PY的帮助文档

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #如何查看2to3.PY的帮助文档 #http://tieba.baidu.com/p/3939904893 ...

  8. Red Hat7.2 上安装 MySQL5.5.58

    1.首先查看linux版本:cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.2 (Maipo) 2.Linux查看版 ...

  9. Struts2+JSON数据

    待整理 参考 http://yshjava.iteye.com/blog/1333104 http://kingxss.iteye.com/blog/1622455 JSON中,java.lang.N ...

  10. Kettle7.1在window启动报错

    实验环境: window10 x64 kettle7.1  pdi-ce-7.1.0.0-12.zip 错误现象: a java exception has occurred 问题解决: 运行调试工具 ...