Jetty入门
Jetty的入门
一、开发环境
Eclipse 4.3.1
Maven 3.1
Jetty 9.0.6.v20130930
Jetty的下载地址:
http://download.eclipse.org/jetty/
二、新建Maven项目
1、新建webapp项目jettytest.
2、在Pom.xml中配置Jetty dependency和plugin
<!-- Jetty begin -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.0.6.v20130930</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.0.6.v20130930</version>
</dependency>
<!-- Jetty end -->
<plugins>
<!-- compiler插件, 设定JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
三、新建SimpleServlet和JettyServer
1、新建一个简单的Servlet:SimlpeServlet
public class ServletServer {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new SimpleServlet()), "/firstservlet");
context.addServlet(new ServletHolder(new SimpleServlet("Hello, this is my first Jetty servlet!")), "/secondservlet");
server.start();
server.join();
}
}
2、新建JettyServer
public class SimpleServlet extends HttpServlet {
private static final long serialVersionUID = -8470943914753284049L;
private String message = "Hello World!";
public SimpleServlet() {
}
public SimpleServlet(String message) {
this.message = message;
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String password = request.getParameter("password");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>" + message + "</h1>");
if (name != null) {
response.getWriter().println("名字:" + name + "</br>");
}
if (password != null) {
response.getWriter().println("密码:" + password + "</br>");
}
}
}
四、运行结果
1、运行JettyServer,启动Jetty服务器。控制台出现下列信息表示服务器启动成功:
2013-10-12 22:20:36.281:INFO:oejs.Server:main: jetty-9.0.6.v20130930
2013-10-12 22:20:36.312:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@18c2661{/,null,AVAILABLE}
2013-10-12 22:20:36.406:INFO:oejs.ServerConnector:main: Started ServerConnector@838143{HTTP/1.1}{0.0.0.0:8080}
2、打开浏览器输入地址:http://127.0.0.1:8080/firstservlet。出现下列运行结果:

3、还可以输入地址:http://127.0.0.1:8080/secondservlet。出现下列运行结果:

五、大功告成!
Jetty入门的更多相关文章
- Jetty入门(1-3)Eclipse集成gradle-Gretty插件或maven-jetty插件运行应用
英文来源: http://akhikhl.github.io/gretty-doc/Getting-started.html 一.gradle插件 1.使用gretty来运行jetty: gradl ...
- Jetty入门(1-2)eclipse集成jetty插件并发布运行应用
一.eclipse集成jetty插件 1.从市场安装jetty插件 2.使用jetty插件发布应用和配置运行环境 debug配置默认共用上述run配置 3.使用jetty插件启动运行和停止运行选中的应 ...
- Jetty入门(1-1)Jetty入门教程
一.Jetty是什么? 1.Jetty 是一个Java语言编写的,开源的Servlet容器和应用服务器. Jetty 极度轻量级.高便携性.功能强大.灵活和扩展性好,而且支持各种技术如SPDY.Web ...
- jetty 入门
jetty因其能作为内嵌的应用服务器,随应用一起存在,在小批量应用中很受欢迎. jetty作为应用服务器: jetty下载: 在官网下载jetty:http://www.eclipse.org/jet ...
- Jetty使用教程(四:21-22)—Jetty开发指南
二十一.嵌入式开发 21.1 Jetty嵌入式开发HelloWorld 本章节将提供一些教程,通过Jetty API快速开发嵌入式代码 21.1.1 下载Jetty的jar包 Jetty目前已经把所有 ...
- Jetty官方文档翻译
最近在学习Jetty,没有找到合适的资料,所有只能看官方文档了,但是只有英文的,想着自己翻译着学也是学还不如把学习的过程放到网上,也可以给需要的人看,英文水平毕竟有限,也是用有道翻译着来的,不过也加了 ...
- Jetty 服务器的知识
Jetty 服务器的知识 也许你还没有听说过这个Jetty服务器,不过它确实是一种比较轻量级的Java服务器,和Tomcat一样,专门解释JavaWeb程序的服务器.因为在之前学习Java Web 的 ...
- Jetty总览
Jetty入门 基本功能介绍 配置概览-怎么配置Jetty 配置概览-须要配置什么 Jetty配置 部署到Jetty 配置上下文 配置连接器 配置安全 配置JSP支持 Jetty管理指导 启动Jett ...
- Servlet引擎Jetty之入门1
Jetty与tomcat一样,HttpWeb容器,支持实现Servlet规范. 详细介绍参考:https://www.ibm.com/developerworks/cn/java/j-lo-jetty ...
随机推荐
- python学习笔记(一)
1. BeautifulSoup是一个很好用的Python写的一个HTML/XML的解析器,它可以处理不规范标记并生成剖析树(parse tree).Beautifulsoup可以对便签Object进 ...
- iframe中的js
iframe之间的js是不能相互访问的,iframe和父窗体之间的js也是不能相互访问的
- jsp request 对象详解
转自:http://www.cnblogs.com/qqnnhhbb/archive/2007/10/16/926234.html 1.request对象 客户端的请求信息被封装在request对象中 ...
- js 淡入淡出的图片
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java 标识符命名规则
标识符:就是给类,接口,方法,变量等起名字. 组成规则: A:英文字母大小写 B:数字字符 C:$和_ 注意事项: A:不能以数字开头 B:不能是Java中的关键字 C:Java语言严格区分大小写 包 ...
- Failed to load the JNI shared library jvm.dll
jdk和使用的ide版本不符合,换一个版本的jdk或者换版本的ide
- 搭建高可用mongodb集群(转)
搭建高可用mongodb集群(一)——配置mongodb 搭建高可用mongodb集群(二)—— 副本集 搭建高可用mongodb集群(三)—— 深入副本集内部机制 搭建高可用mongodb集群(四) ...
- 2.openssl rsa/pkey
分别是RSA密钥的处理工具和通用非对称密钥处理工具.它们用法基本一致,所以只介绍openssl rsa. [root@xuexi tmp]# man rsa NAME rsa - RSA key pr ...
- python(第五步django)
这是一个关于,web开发的库, 下一步需要重点掌握的是,网页跳转和数据展示,和面向对象的关系的重用的内容 1:目前掌握的是project 的创建,和app的创建, 2:
- UART UVM验证平台平台搭建总结
tb_top是整个UVM验证平台的最顶层:tb_top中例化dut,提供时钟和复位信号,定义接口以及设置driver和monitor的virual interface,在intial中调用run_te ...