ǰλ: ҳ > >

Filter*-¼

ʱ:

ҳͨ·ļֱӷʣڰȫǣʹFilter*أжǷѾ¼ת½ҳͨʵFilterؼ


private FilterConfig config = null;
?? ?@Override
? ? public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
? ? ? ? ? ? throws IOException, ServletException {
?? ??? ?
? ? ? ? HttpServletRequest request1 = (HttpServletRequest)request;
? ? ? ? HttpServletResponse response1 = (HttpServletResponse)response;
? ? ? ? HttpSession session = request1.getSession();
? ? ??
? ? ? ? request.setCharacterEncoding("UTF-8");
? ? ? ? response.setContentType("text/html;charset=UTF-8");
? ? ? ? Users user = (Users) session.getAttribute(Conts.SESSION_NAME);
? ? ? ? String pat = request1.getRequestURI();


? ? ? ? //!pat.endsWith("login.jsp") ˵¼ҳ


? ? ? ? if(null == user && !pat.endsWith("login.jsp")){
? ? ? ? ?? ?System.out.println("ûе¼");
? ? ? ? ? ? response1.sendRedirect(request1.getContextPath()+"/login.jsp");
? ? ? ? } else{
? ? ? ? ?? ?System.out.println("Ѿ¼");
? ? ? ? ?? ?chain.doFilter(request,response);
? ? ? ? }
? ? }


web.xml


?
? ? control
? ? com.sms.servlet.control
?

?
? ? control
? ? *.jsp
?
?


Ą̊́еjspҲд?/xxxĿ¼ʾĿ¼ļ


Conts.SESSION_NAME һ̬SESSIONں޸ £
public class Conts {
?? ?public final static String SESSION_NAME = "Login";
}



ӣ