Detailed description of filter selection in jsp, and detailed description of jsp filter selection
Example:
Public class LoginCheckFilter implements Filter {private FilterConfig config = null; private String webroot = null; public void destroy () {// TODO Auto-generated method stub} @ Overridepublic void doFilter (ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, servletException {// TODO Auto-generated method stubHttpServletRequest request = (HttpServletRequest) req; HttpServletResponse Response = (HttpServletResponse) resp; HttpSession session = request. getSession (false); // gets the session of the current session. No session is created or the session is created. same as getSession () String url = request. getRequestURI (); // get the current input/project/the current access path is the same as the defined path if (url! = Null & url. equals (webroot + "/login. jsp ") & url. equals (webroot + "/LoginServlet") {chain. doFilter (req, resp);} else {if (session = null) {response. sendRedirect (webroot + "/login. jsp ");} else {String user2 = (String) session. getAttribute ("user1"); if (user2 = null) {response. sendRedirect (webroot + "/login. jsp ");} else {chain. doFilter (request, response) ;}}}@ Overridepublic void init (FilterConfig config) throws ServletException {// TODO Auto-generated method stubthis. config = config; ServletContext ctx = config. getServletContext (); // get url/project name webroot = ctx. getContextPath (); // project name }}
Note that the LoginServlet jump to the welcome page is a client jump.
In the above jsp, the detailed description of the filter selection method is all the content shared by the editor. I hope to give you a reference and support for the help house.