package com. Java1234. Filter;
import java.io.IOException;
The import javax.mail. Servlet. The Filter;
The import javax.mail. Servlet. FilterChain;
The import javax.mail. Servlet. FilterConfig;
The import javax.mail. Servlet. ServletException;
The import javax.mail. Servlet. ServletRequest;
The import javax.mail. Servlet. ServletResponse;
import javax.servlet.http.HttpServletRequest;
The import javax.mail. Servlet. HTTP. HttpSession;
Public class LoginFilter implements Filter {
Public void destroy () {
//TODO Auto - generated method stub
}
Public void doFilter (ServletRequest ServletRequest and ServletResponse ServletResponse,
FilterChain FilterChain) throws IOException, ServletException {
It request=servletRequest (it);
The HttpSession session=request. GetSession ();
The Object o=session. The getAttribute (" currentUser ");
String path=request. GetServletPath ();
If (o==null& & Path. IndexOf (" login ") & lt; 0 {
Request. GetRequestDispatcher (" login. JSP "). The forward (servletRequest, servletResponse);
} else {
FilterChain. DoFilter (servletRequest, servletResponse);
}
}
Public void init (FilterConfig arg0) throws ServletException {
//TODO Auto - generated method stub
}
}
& lt; ? The XML version="1.0" encoding="utf-8"?>HeadFirstJspServletChap05 & lt;/display - name> Index. Html Index. Htm Index. Jsp Default. Html Default. Htm Default. Jsp HelloWorldServlet Com. Java1234. Web. HelloWorldServlet
HelloWorldServlet /helloWorld
LifeServlet Com. Java1234. Web. LifeServlet
LifeServlet /life
RedirectServlet Com. Java1234. Web. RedirectServlet
RedirectServlet /redirect
ForwardServlet Com. Java1234. Web. ForwardServlet
ForwardServlet /forward
LoginServlet Com. Java1234. Web. LoginServlet
LoginServlet /login
LogoutServlet Com. Java1234. Web. LogoutServlet
LogoutServlet /logout
LoginFilter Com. Java1234. Filter. LoginFilter
LoginFilter /* & lt;/url - pattern>
Com. Java1234. Listener. SessionAttributeListener
CodePudding user response:
The debugger to see itnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull