设为首页收藏本站

Scripts 学盟

 找回密码
 加入学盟

QQ登录

只需一步,快速开始

查看: 973|回复: 0
打印 上一主题 下一主题

实战 Jetty Demo [复制链接]

Rank: 8Rank: 8

跳转到指定楼层
1#
那个谁 发表于 2012-10-24 13:51:53 |只看该作者 |倒序浏览
这个是我最近研究的Demo,开源与大家!
坑爹的不能大于2M的附件,没法传啊,jar都10M了。
简单贴下代码吧:
                                ContextHandlerCollection contexts= new ContextHandlerCollection();
		Context context = new WebAppContext(this.getClass().getResource("/").getPath()+ "webapp", "/");//webapp网站的html文件目录
		context.setWelcomeFiles(new String[] { "index.jsp" }); //欢迎页
		contexts.addHandler(context);
		
		adminHost ="127.0.0.1"; //绑定的IP地址
		adminPort =8089; // 使用的http端口
		adminServer = new Server();
		adminServer.setSendServerVersion(false);
                                if (adminPort > 0) {
			Connector httpConnector = new SelectChannelConnector();
			httpConnector.setHost(adminHost);
			httpConnector.setPort(adminPort);
			adminServer.addConnector(httpConnector);
		}
		if (adminServer.getConnectors() == null
				|| adminServer.getConnectors().length == 0) {
			adminServer = null;
			log.warn("Admin console not started due to configuration error.");
			return;
		}

		adminServer.setHandlers(new Handler[] { contexts, new DefaultHandler() });

		try {
			adminServer.start();  //启动
			adminServer.join();  //以线程方式启动,不然出错看不到错误信息的。
			httpStarted = true;
			log.debug("Admin console started.");
		} catch (Exception e) {
			log.error("Could not start admin conosle server", e);
		}


然后就访问试试吧
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
分享分享0 收藏收藏0
您需要登录后才可以回帖 登录 | 加入学盟

手机版|Scripts 学盟   |

GMT+8, 2024-5-20 08:44 , Processed in 1.061506 second(s), 11 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部