Small white Study the arduous course!
I'm only talking about the latest version of Eclipse since servelt3.0 Servelt and filter Do not have to be configured in Web. XML, personal understanding of Servelt and filter is not too deep, but since servelt3.0, you set up the Servelt is not self-configuration, automatically configured for you (of course, you need to build with eclipse in the new servelt not you build a Class and then inherit the method in Servelt! Filter also does not need to be configured in Web. XML, just configure it in the filter file you created ...
How to configure the key as follows:
@WebFilter (asyncsupported = true, Urlpatterns = {"/loginfilter", "/succ.jsp", "Here you can write the page you want to filter}")
If you are a 3.0 later version you can see these words in the beginning! Urlpatterns behind write you want to filter the page must pay attention to the format (I found no matter how many folders you create, just write the file name you want to filter and a slash on the line, you can identify, I do not understand, haha ha)
The following dofilter methods are as follows
Public voidDoFilter (servletrequest request, servletresponse response, Filterchain chain) throws IOException, Servletexception { //TODO auto-generated Method Stub//Place your code hereHttpServletRequest httprequest=(httpservletrequest) request; HttpServletResponse HttpResponse=(httpservletresponse) response; HttpSession Session=httprequest.getsession ();//I used a session in front to determine if the user is logged in!! Here to get the value, if not empty can jump!! if(Session.getattribute ("Succe")!=NULL) {System. out. println ("this one only thought once."); Chain.dofilter (request, response);//release can pass}Else{System. out. println ("page redirection was used once");Httpresponse.sendredirect ("You need to redirect the page"///here to jump to the login interface you need . } }
Of course, this I Baidu for a while, saw a lot of big guy's blog, thank them for their own study of a bit---share the experience!
Java Web The most convenient configuration filter method, how exactly is the filter configured?