【Servlet】使用org.eclipse.jetty实现小型的Servlet服务器
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服务器的更多相关文章
- 使用Spring Boot操作Hive JDBC时,启动时报出错误:NoSuchMethodError: org.eclipse.jetty.servlet.ServletMapping.setDef
使用Spring Boot操作Hive JDBC时,启动时报出错误:NoSuchMethodError: org.eclipse.jetty.servlet.ServletMapping.setDef ...
- Jetty启动报错排查org.eclipse.jetty.util.MultiException: Multiple exceptions
最近自己搭建了一个spring的项目,使用Maven做项目构建,使用JDK8,为了方便启动就使用jetty作为启动容器,但是却无意间步入了一个坑 [WARNING] Failed startup of ...
- maven eclipse jetty debug
可以通过查看最近版本: http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server http://search.maven.org ...
- java.lang.ClassNotFoundException: org.eclipse.jetty.plus.webapp.EnvConfiguration
最近刚接触jetty,在myeclipse8.6中加入了一个项目,运行时就出了这个java.lang.ClassNotFoundException: org.eclipse.jetty.plus.we ...
- eclipse jetty启动内存溢出
一.eclipse jetty启动内存溢出, 异常信息 Exception in thread "ConfigClientWorker-Default" java.lang.Out ...
- 【转】Eclipse中创建并运行Servlet项目
最近看了写http协议的学习资料,因此想要实现下andriod平台和服务器通信,那就servlet吧,哎哟,还不错哦!顺便说下,我这个servlet服务是想获得用户名和密码进行校验,然后反给客户端状态 ...
- Eclipse Jetty插件安装
Eclipse Jetty插件安装 使用方法一: 本地资源包插件下载地址:http://pan.baidu.com/s/1sjNP5Id 或者是地址:http://pan.baidu.com/s/1b ...
- org/eclipse/jetty/server/Handler : Unsupported major.minor version 52.0
注:本文来源于<org/eclipse/jetty/server/Handler : Unsupported major.minor version 52.0> Exception in ...
- JFinal启动报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Connector
- 错误: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/ ...
随机推荐
- wamp设置自定义域名访问php网站
wamp是一个在window系统下很不错的php开发套件,一般我都是使用此套件在本地进行开发和测试的 特别是alias功能特别好,可以同时开发N个php网站而不互相影响 但alias有一个问题,它其实 ...
- Eclipse QuickSear的插件的说明
https://spring.io/blog/2013/07/11/eclipse-quick-search Eclipse QuickSear的插件的说明
- mac切换root
方法一: sudo -i sudo su或是su. 转自:http://blog.csdn.net/duanyipeng/article/details/8621967
- eclipse插件大全
http://www.cnblogs.com/homezzm/archive/2009/11/27/1612054.html
- php获取当前时间的方法
1.获取当前时间 date('Y-m-d H:i:s', time()) 2.字符串转时间 date('Y-m-d H:i:s',strtotime('2018-8-21 22:00:00'))
- MSSQL 2005/2008 日志压缩清理方法小结
适用于SQL Server 2005的方法 --------------------------------------------- 复制代码 代码如下: USE DNName GO 1,清理日志 ...
- http支付导图流程
第三方提交数据到官方的URL(加带参数)---官方服务器处理完成---跳转到第三方URL(加带参数)---第三处理---结束
- Qt,Qt/E,Qtopia Core, Qtopia之间的区别和联系
转自:http://www.qtcn.org/bbs/read.php?tid=10373 关于Qt,Qt/E,Qtopia Core, Qtopia这些版本之间的区别和联系: Qt泛指Qt的所有桌面 ...
- SQL Server排序规则不一致 - Collate Database_Default
http://www.cnblogs.com/chencidi/archive/2014/07/02/3820386.html 使用多库查询时会出现排序规则冲突的问题 解决办法 在字段后面添加Coll ...
- Android使用OKHttp库实现视频文件的上传到服务器
目录 1 服务器接口简介 2 Android端代码实现 2.1 xml布局文件 2.2 Activity类 2.3 Okhttp网络通信类 1 服务器接口简介 此处我使用的服务器接口是使用Flask编 ...