这个是我最近研究的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);
}
然后就访问试试吧 |