问题描述
- fiter可以过滤jsp等后缀的url,但就是过滤不了.do请求,fiter该怎么写 求帮忙
-
/*public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { // 获得在下面代码中要用的request,response,session对象 log.info(".....ThirdPartyStoresFilter...doFilter....."); HttpServletRequest servletRequest = (HttpServletRequest) arg0; HttpServletResponse servletResponse = (HttpServletResponse) arg1; HttpSession session = servletRequest.getSession(); String user =(String) session.getAttribute("username"); // 获得用户请求的URI String path = servletRequest.getRequestURI(); System.out.println(servletRequest.getRequestURL()+"(00000000"); // 登陆页面无需过滤 if (path.indexOf("/login.jsp") > -1 || path.indexOf("/images") > -1 || path.indexOf("/js") > -1 || path.indexOf("/style") > -1) { arg2.doFilter(arg0, arg1); return; } //得到上下文路径 String returnUrl = servletRequest.getContextPath(); try { // 判断如果没有取到员工信息,就跳转到登陆页面 if (StringUtils.isBlank(user)) { // 跳转到登陆页面 servletResponse.sendRedirect(returnUrl + "/shop/login.jsp"); } else { // 已经登陆,继续此次请求 arg2.doFilter(arg0, arg1); } } catch (Exception e) { servletResponse.sendRedirect(returnUrl + "/shop/login.jsp"); } } <filter> <filter-name>filter</filter-name> <filter-class>...</filter-class> </filter> <filter-mapping> <filter-name>filter</filter-name> <url-pattern>/shop/*</url-pattern> </filter-mapping> */
解决方案
你是不是还用了 struts啊? .do 请求应该是被它给拦截了
解决方案二:
A URL pattern is a URI that is relative to the application context. Patterns can include:
Path mapping, starting with / and ending with /*
This pattern identifies any resource that starts with a given path, for example: /catalog/* or /europe/poland/*
Extension mapping, starting with *.
This pattern identifies any resource with the given extension, for example, *.jsp or *.gif
Default servlet mapping, containing only / This pattern identifies the default servlet of the application.
Exact matches
This pattern uses a string that represents a specific resource, for example, /snoop is a servlet mapping and /list/banner.jsp is a file mapping.
So if you need mapping like /secure*, you need either redesign your app to /secure/* so each resource will be a subpath, or apply multiple patters to one web resource collection like /secureA , /secureB, /secureEtc
解决方案三:
struts1没用过,对于struts2还是比较熟悉,struts2只要配置了filer拦截器所有的请求都会先进入拦截器的包括静态资源,只有在filer(拦截器)里面doFilter(放行)的才不拦截,建议把配置贴出来看看,拦截器是根据配置的url目录拦截的,/* 拦截所有请求
解决方案四:
看看你的web.xml配置是不是对请求后缀做了限制
时间: 2024-12-28 05:36:38