Jetty启动
2016-04-12 22:07
183 查看
package Jetty; import org.eclipse.jetty.server.NetworkTrafficServerConnector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; //import org.eclipse.jetty.server.NetworkTrafficServerConnector; //import org.eclipse.jetty.server.Server; //import org.eclipse.jetty.webapp.WebAppContext; public class JettyStart { /* (1) get请求 编码默认使用 UTF-8 编码, * 可以通过 request.setAttribute(“org.eclipse.jetty.server.Request.queryEncoding”,”GBK”) 设定查询参数的编码, * 如果不设定则默认读取系统属性 -Dorg.eclipse.jetty.util.URI.charset=GBK 的编码,如果系统属性也没有设定,则默认为 UTF-8 。 * (2)POST 参数默认使用 Content-type 中的 Charset 编码,如果 Charset 没有,则默认使用 UTF-8 编码, * 当然可以在使用之前使用 request.set CharacterEncoding 设定编码。 */ public static void main(String[] args) throws Exception { //新建一个server,设置端口号 Server server = new Server(8888); //想向server中添加一二Connector,可单独设置IP和端口 NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(server); connector.setHost("localhost"); connector.setPort(7777); server.addConnector(connector); //设置jetty的工作目录。(取得一个context环境,并添加到server中) new JettyStart(); String currentClassPath = JettyStart.class.getResource("/").getPath(); // String webPath = currentClassPath.substring(0, currentClassPath.indexOf("com.spring.web")) + "com.spring.web/src/main/webapp"; String webPath = currentClassPath.substring(0, currentClassPath.indexOf("com.spring.web")) + "com.spring.web"; WebAppContext context = new WebAppContext(webPath, "/"); server.setHandler(context); //设置XX东西,哎,不深入了解 server.setStopAtShutdown(true); server.start(); server.join(); } }
POM.XML
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.8.v20160314</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.3.8.v20160314</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.8.v20160314</version>
</dependency>
相关文章推荐
- shop++ 4.0项目配置
- 学习资料网站汇总__不断更新
- 【Android测试】【随笔】与 “58同城” 测试开发交流
- TCO/IP卷一(第三章学习)
- hdu 1907 && hdu 2509(Nim博弈)
- 【JAVA实现】单例模式(singleton)
- NYOJ 301 递推求值【矩阵快速幂】
- php连接sqlserver的方法
- hive2.0.0安装
- Nios II ‘Launching New_configuration’ has ecountered a problem.Dowenloading Elf Process failed问题解决
- CSUST 第九届校赛C-编辑距离(DP)
- 四轴飞行器的进阶
- c++第三次实验(个人所得税)
- bzoj4293 [PA2015]Siano
- 内部类分类介绍JAVA224-225
- C++作业(三)
- 关于Struts中结果类型chain的理解
- Laravel5 技能介绍(坑的清单)
- JS中Attribute 和 property的区别
- 六、安装xcache3.1.2,为php加速