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 ...
随机推荐
- finder的隐藏文件&IOS虚拟机地址
在终端里输入下面命令即可让它们显示出来. defaults write com.apple.finder AppleShowAllFiles -bool true 如果想恢复隐藏,可以用这个命令: ...
- VBA_Excel_教程:变量,数组
Sub testVar() '变量 Dim strT1 As String strT1 = "A" '常量[加不加类型都可以] Const strT2 As String = &q ...
- 三、Distributing Maya Plugins
For example, a fully implemented render utility node will have at least three files: the plug-in fil ...
- 2017/1/8 C语言程序练习d
有10个数按由小到大顺序存放在一个数组中,输入一个数,要求用折半查找法找出该数是数组中第几个元素的值.如果该数不在数组中,则打印出"无此数". 输入:-12 -8 12 24 45 ...
- [转载:]Fortran 二进制文件读写
一些朋友总是咨询关于二进制文件的读写和转化.这里就我自己的理解说一说. 一).一般问题 二进制文件与我们通常使用的文本文件储存方式有根本的不同.这样的不同很难用言语表达,自己亲自看一看,理解起来会容易 ...
- 浅谈OpenGL变换矩阵
OpenGL中使用的矩阵全为列向量为主的矩阵. 参考OpenGL变换网站为 http://www.songho.ca/opengl/gl_transform.html 1.什么是GL_MODELVI ...
- JAVA编程规则【转自java编程思想】
本附录包含了大量有用的建议,帮助大家进行低级程序设计,并提供了代码编写的一般性指导: (1) 类名首字母应该大写.字段.方法以及对象(句柄)的首字母应小写.对于所有标识符,其中包含的所有单词都应紧靠在 ...
- delphi Tab Item Badge Value 消息数标记
https://community.embarcadero.com/blogs?view=entry&id=9074 unit TabBadgeFrm; interface uses Syst ...
- java获取当前执行文件的路径
需要知道执行jar包时,jar包所在的路径. 开始使用了 p.getClass().getResource("/").getPath(); 结果在IDE里面使用是好的,但是在命令行 ...
- Centos下MySQL使用总结
转载于CentOS中文站:http://www.centoscn.com/CentOS/Intermediate/2013/0817/1334.html 一.MySQL安装 Centos下安装mysq ...