当前位置: 代码迷 >> Java Web开发 >> 登录后访问设置请问
  详细解决方案

登录后访问设置请问

热度:4028   发布时间:2013-02-25 21:16:04.0
登录后访问设置请教
<filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>/user/member/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  </filter-mapping>  
这个设置了,但是过滤器内或者filters内如何写
Java code
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    }      }


------解决方案--------------------------------------------------------
你重新启动下服务器就ok了
  相关解决方案