在我的JSF应用程序中,我想实现一个web过滤器来更改所用设备函数中的请求视图(我使用spring-mobile设备解析器)。
我的过滤器里有这个:
String requestURI = request.getRequestURI();
Device device = DeviceUtils.getCurrentDevice(request);
if (!requestURI.contains("/mobile") && device.isMobile()) {
String newUri = requestURI.replace("/contextroot/faces/html/", "/contextroot/faces/html/mobile/");
request.getRequestDispatcher(newUri).forward(request, response);
}
else {
filterChain.doFilter(request, response);
}但我得到了一个例外
/contextroot/faces/html/mobile/consult/consult.xhtml Not Found in ExternalContext as a Resource我做错了什么?
发布于 2013-10-30 18:14:32
HttpServletRequest#getRequestDispatcher()采用相对于上下文根的路径,因此不应该包含上下文根本身的路径。这在javadoc (我的重点)中有明确的规定:
...
指定的路径名可以是相对的,尽管它不能扩展到当前servlet上下文之外。如果路径以"/“开头,则解释为相对于当前上下文根。如果servlet容器不能返回RequestDispatcher,则此方法返回null。
...
https://stackoverflow.com/questions/19246738
复制相似问题