【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/ ...
随机推荐
- 3d打印机的软件系统组成部分
主要由计算机.应用软件.底层控制软件和接口驱动单元组成1)计算机一般采用上位机和下位机两级控制.其中上位主控机一般采用配置高.运行速度快的PC机:下位机采用嵌入式系统DSP,驱动执行机构.上位机和下位 ...
- Is there anyway to discover which ip addresses are connected to the db?
From mongo shell run db.currentOp() to show all active connections or db.currentOp(true) to show all ...
- [Functional Programming + React] Provide a reasonable default value for mapStateToProps in case initial state is undefined
For example we have a component, it needs to call 'react-redux' connect function. import { compose, ...
- maven 打包可执行jar的方法
转自:http://blog.csdn.net/johnnywww/article/details/7964326 1.修改pom.xml增加如下内容 <plugin> <group ...
- 面试总结——Java高级工程师(三)
https://blog.csdn.net/moneyshi/article/details/53086927
- 微信小程序 - loading(组件)
更新日期: 2019/3/8:首次发布 2019/3/12:增加loadOpacity透明度控制,默认0.5. 以及修改居中方式 Loading 参数: 1. type:loading(必需参数) 2 ...
- Windows服务安装与控制
Windows服务安装与控制 1.建立服务 (1)定义一个ServiceInstaller using System; using System.Collections.Generic; using ...
- 运用BufferedWriter把数据写入文件
public class WriteReadFiles { private static Logger log = LoggerFactory.getLogger(WriteReadFiles.cla ...
- reStructuredText - 一个比MarkDown更好用的标记语言
文档和教程 http://docutils.sourceforge.net/rst.html http://zh-sphinx-doc.readthedocs.io/en/latest/rest.ht ...
- TOEIC真题学习
01.The old-fashioned delicatessen inside the street has become a popular place for lunch 街道里面的熟食店正在成 ...