jetty配置文件详解(二)
tring target, HttpServletRequest request, HttpServletResponse response, int dispatch)
throws IOException, ServletException {
if (_handlers!=null && isStarted())
{
MultiException mex=null;
//遍历当前的所有handler,用他们都来处理一下这个请求
for (int i=0;i<_handlers.length;i++) {
try{
_handlers[i].handle(target,request, response, dispatch);
}
catch(IOException e)
{
throw e;
}
catch(RuntimeException e)
{
throw e;
}
catch(Exception e)
{
if (mex==null)
mex=new MultiException();
mex.add(e);
}
}
if (mex!=null)
{
if (mex.size()==1)
throw new ServletException(mex.getThrowable(0));
else
throw new ServletException(mex);
}
}
}
代码很简单吧,就是遍历当前保存的所有的handle,一次调用他们的handle方法。。。也就是说每一次http请求接收到以后,都会调用上面3个handler的handle方法来依次处理。。。
其实这里的handler配置会对整个jetty服务器的性能产生比较大的影响。。。
如果我们只是部署一个应用在jetty的话,那么我们可以将WebAppContext前面的ContextHandlerCollection去掉,这样就可以少了一层path的匹配。。。
最精简的情况下我们可以这么高配置:
[java]
将server的handler属性直接设置为一个WebAppContext对象,同时设置这context的path,以及app的路径什么的。。。这样子性能应该是最好的了。。毕竟省去了很多其余的处理过程。。
好了,到这里整个jetty的配置文件最重要的一些内容就算是差不多了。。。接下来还有一些其他的配置,不过基本上都能够很容易搞懂的。。。
总的来说整个jetty的配置还算是比较简单的,现在感觉到如果真的要用好一个东西,对其的实现由一定的了解是很有帮助的。。。