登录后访问设置请教
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/user/member/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
这个设置了,但是过滤器内或者filters内如何写
package filters;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class LoginFilter implements Filter{ public void init(FilterConfig conf) throws ServletException{ } } public void doFilter(ServletRequest req,ServletResponse res, FilterChain chain) throws ServletException,IOException{ HttpServletRequest hReq = (HttpServletRequest)req; HttpServletResponse hres=(HttpServletResponse)res; HttpSession s = hReq.getSession(true); Object ac = (Object) s.getAttribute("account"); if(ac==null){ ((HttpServletResponse)res).sendRedirect("/user/loginForm"); //是在这里加吗?改如何写请教下 } chain.doFilter(req,res); } public void destroy(){ // TODO Auto-generated method stub } }