首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

登录后访问设置请问

2012-08-13 
登录后访问设置请教filter-mappingfilter-nameLoginFilter/filter-nameurl-pattern/user/member/*

登录后访问设置请教
<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了

热点排行