我看论坛上得帖子都是在一个main方法中用一个线程启动了jetty服务器,以后就直接开发jsp文件了.但是我有个需求:就是希望这个main方法里面包含一个功能,当接收到用户一个请求(例如: /webapp/stopserver?stop=true),就停止服务器! 调用可以有一种方法,就是jetty监听一个http请求,接收到了,就调用 Server.stop()方法停止服务器, 比如:
if(request.getParameter(stop).equals("true")){
Server.stop();
} //类似这样逻辑调用
Tomcat是可以做到得,但是现在得main方法里面不知道怎么操作 request对象,从而达到上面得目的?
现在main方法:
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
// 创建Jetty HttpServer对象
Server server = new Server();
BoundedThreadPool threadPool = new BoundedThreadPool();
threadPool.setMaxThreads(100);
server.setThreadPool(threadPool);
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
WebAppContext context = new WebAppContext("webapp", "/webapp");
server.addHandler(context);
server.setStopAtShutdown(true);
server.setSendServerVersion(true);server.start(); server.join(); }
我可以另启一个线程,然后把Server传入,关闭他,但是我在Jetty代码里面无法得到HttpServeltRequest对象!! 如何得到请求参数呢? 有人了解这个用法得么?谢谢!