官方的Druid插件集成的非常好了,之前一直在jetty开发,没有设置项目路径,现在由于项目需要部署到Tomcat,并且区分一个域名下的几个项目,所以必须要有项目路径,但是加上路径后,druid插件跳转路径不对,一直显示404,跟踪源码发现,DruidStatViewHandler在匹配到路径后,重定向的时候,没有加上ContextPath,所以导致页面一直404,所以,稍微改造下handler就解决啦
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		if (target.startsWith(visitPath)) {
			isHandled[0] = true;
			target=request.getContextPath()+target;//路径加上上下文路径
			if (target.equals(visitPath) && !target.endsWith("/index.html")) {
				HandlerKit.redirect(target += "/index.html", request, response, isHandled);
				return ;
			}
			
			try {
				servlet.service(request, response);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		else {
			next.handle(target, request, response, isHandled);
		}
	}这样就满足我的需求了,暂时没有在jetty去掉项目路径测试,如果做成通用的话就判断下上下文路径就行了,如果有的话就加上,没有就不加,打完收工。
 
 
 
 
 
