Detailed description of filter selection in jsp, and detailed description of jsp filter selection

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.