Jetty启动

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值