jetty嵌入式 webApp开发(Simple Demo)
来源:互联网 发布:人工智能 招聘 深圳 编辑:程序博客网 时间:2024/05/24 16:13
时间可以带走一切 ---路
jetty是一个轻量级的servlet容器,有点类似tomcat,但是用起来比tomcat方便。
jetty下载链接:http://download.eclipse.org/jetty/
我的开发环境 :
操作系统:UBuntu 14.04 LTS
集成工具:Eclipse(Version: Luna Service Release 1 (4.4.1) Build id: 20140925-1800)
jetty版本:jetty-9.2.6
下面让我们进入Hello World之旅吧。
打开eclipse,在【Package Explorer】中单击右键【New】-->【Java Project】,在弹出框中填上工程名称“jettyWebApp”,【Finish】。 如图是建好的工程
按图所示,建好jetty目录和webRoot目录。
工程建好了,现在最重要的不要忘了包依赖,在下载的jetty包中找到如下jar包,并导入包(Referenced Libraries)。
加上javax.el-3.0.0.jar(截图把它截掉了)
以下是源码
Start.java
package start;import org.eclipse.jetty.server.Server;import org.eclipse.jetty.webapp.WebAppContext;public class Start {public static void main(String[] args){Server server = new Server(8080);WebAppContext context = new WebAppContext();context.setContextPath("/jettyWebApp");context.setDescriptor("webRoot/WEB-INF/web.xml");context.setResourceBase("webRoot");context.setParentLoaderPriority(true);server.setHandler(context);try {server.join();server.start();} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>jettyWebApp</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body>hello jetty! 中国!</body></html>
以上操作完了那么一个完整的web工程就建好了,同时也部署得差不多了,就差运行了。打开Start.java,单击右键【Run As】-->【Java Application】。运行结果如下
到此就部署完了。
打开浏览器,在地址栏输入:http://localhost:8080/jettyWebApp/
0 0
- jetty嵌入式 webApp开发(Simple Demo)
- 嵌入式 Jetty 9.0+ 测试demo
- Jetty嵌入式开发
- Jetty 9嵌入式开发
- Jetty 嵌入式开发
- Jetty 9嵌入式开发
- 嵌入式Jetty开发之代码启动Jetty
- Jetty实战(7)之嵌入式Jetty应用Demo
- Jetty嵌入式容器开发实例
- java webapp嵌入jetty
- JETTY嵌入式Web容器的开发
- 【WebApp】webApp开发总结(集合贴)
- 嵌入式jetty
- Simple Demo
- Maven webapp 内嵌 Jetty
- jetty之嵌入式运行jetty
- jetty嵌入式开发中使用ssl连接,ssl证书生成
- 嵌入式服务器jetty,让你更快开发web
- 1152 - 4 Values whose Sum is 0
- 1442 - Cav
- 1451 - Average
- 网站加速--服务器编写篇(转)
- 计算器的实现——基础篇(一)
- jetty嵌入式 webApp开发(Simple Demo)
- 1471 - Defense Lines
- 1605 - Building for UN
- 1606 - Amphiphilic Carbon Molecules
- 1607 - Gates
- 蓝桥杯 - 分糖果 (模拟~)
- 1608 Non-boring sequences
- 1609 Foul Play
- C++11 中一个很有趣的东西,Lambda表达式,称可调用对象,也叫函数对象。