请问我在不知道网站架构的情况下,编写一个filter,只使用HttpServletRequest和HttpServletResponse,能获得HTTP请求要访问的页面文件在服务器上的绝对地址吗?如果有些情况下请求里并没有文件路径,而是将请求提交给serlvet,将网页地址写在了servlet里面,我在filter里又如何获得该网页文件的绝对路径呢?对JAVA了解的不是很深入,请大牛们指教
调试欢乐多
ServletContext context;
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException
{
HttpServletRequest r = (HttpServletRequest)request;
String path = context.getRealPath(r.getRequestURI().toString());
System.out.println(path);
} public void init(FilterConfig filterConfig) throws ServletException
{
// TODO Auto-generated method stub
context = filterConfig.getServletContext();
}
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
web.xml添加如上信息,这样就可以默认到主页了。
貌似如果请求的被重写了url之后这个只能通过配置文件来找真正的url然后再通过真正的url再找物理路径