Customer background
A Provincial Power Grid Company is a wholly owned subsidiary of China Southern Power Grid Co., Ltd. and one of the largest provincial power grid companies in China. The power grid company is engaged in power grid investment, operation and maintenance, power exchange and scheduling, Power Marketing, power equipment sales, commissioning, testing and testing as well as power design, construction, building, materials, scientific research economic entities for business such as tec
Below is the Web logoff login filter I implemented using the servlet filter in my project:
Package com.sunfairs.filter; Import java.io.IOException; Import Java.util.Date; Import Javax.servlet.Filter; Import Javax.servlet.FilterChain; Import Javax.servlet.FilterConfig; Import javax.servlet.ServletException; Import Jav
Dofilter (ServletRequest request, Servletresponse resp Onse, Filterchain chain) throws IOException, servletexception {//Get Request,response,session object to be used in the following code Httpservle
Trequest ServletRequest = (httpservletrequest) request;
HttpServletResponse servletresponse = (httpservletresponse) response;
HttpSession session = Servletrequest.getsession ();
Gets the URI String path = Servletrequest.getrequesturi () of the user request; System.out.pRINTLN (path);
Take
First do the site need to login verification, turn from: http://blog.csdn.net/daguanjia11/article/details/48995789Filter:Filter is a server-side component that is used to filter Web requests. When a Web request occurs, the Web container first checks that the requested URL ha
Path.contains ("login.jsp") anyway how accurate how to come not to say moreif (Path.indexof ("/login.jsp") >-1) {//Note: Login page must not filter or filter on ... Self-commissioning Don't be lazy! It's a deep memory.Arg2.dofilter (req, resp);Return} else {//If the filter is not login.jspif (password = = NULL | | "".
Filter IntroductionQuestion: What is filter and what can it do?1. From two aspects to resolve what is a filter?1. The function can help us to filter the request and response operation.2. An interface defined by the technology sun Company, Javax.servlet.FilterWhat can 2.Filter
. It also provides a good illustration of how each filter intercepts the sequence of events within the WEB server framework.VariantIn most cases, the filter is passive in this sense because the filter operates the context but does not affect the execution flow. However, if a filter
) throws Servletexception {System.out.println ("Call initialization Method");}}B. Configure Web. XML to specify the resources that need to be filtered. (Quite similar to the configuration of the servlet)2, the implementation process of the filter (life cycle)Life cycle:Birth: An instance of a filter is instantiated and initialized when the application is loaded.S
=Req.getrequesturi (); //get the field as a judge in the sessionstring pwd = (string) session.getattribute ("passwd"); //determine if the requested path contains a request for a login page//if it contains, then do not filter to continue the Operation if(Path.indexof ("/back/login.do") > 1) {Filterchain.dofilter (req, resp); } Else { //If not included, then it is necessary to determine whe
(uri.indexof ("background") !=-1) {// Filter Boolean if background is included in uri doFilter=true;for (Strings:notfilter) {if (Uri.indexof (s) NBSP;!=NBSP;-1) {// do not filter dofilter=false;break if the URI contains a URI that is not filtered;}} if (doFilter) {// perform filtering// get the login entity objectobj=request.getsession () from the session. GetAt
Login filter class;
Public class loginfilter implements filter {
Private filterconfig config;Private string logon_page;Private string home_page;Public void destroy (){Config = NULL;}Public void Init (filterconfig) throws servletexception {// Retrieve the URI of the logon page and homepage from the deployment descriptorConfig = filterconfig;Logon_page = filterconf
filter provides a Filterconfig object that provides related operations:For example, obtain the initialization parameters configured in Filter web. XML configuration:In the Init () method, get:@Overridepublic void init (Filterconfig filterconfig) throws Servletexception { //Get filter initialization parameter Str
first, what is a servlet filter? Servlet filters are small WEB components that intercept requests and responses to view, extract, or somehow manipulate data that is being exchanged between the client and server. Filters are WEB components that typically encapsulate some functionality, though important, but are not conclusive for processing client requests or send
Web parts are very powerful and flexible, and enable you to do the following:
Filter by a fixed value by entering text, numbers, or dates, or by selecting an item from a list of values.
Derive the values to filter by manual data entry or from an external data source, such as a Windows SharePoint Services list, the business data catalog, Microsoft SQL Server 2
log out.
In J2EE, j_security_check servlet is specified for login authentication. Although no servlet is specified for cancellation, this servlet is defined in was, that is, ibm_security_logout, the usage process is similar to the use of j_security_check described earlier. The Code is as follows:
Most application servers do not implement such Servlets, but we can manually simulate the was logout process. The principle is to first obtain httpsession
Analysis of automatic website login operations. I use the CSDN user login function as an example to describe how,
1. Enter the csdn logon interface address: The CSDN User Logon interface is as follows:
2. Enter the correct user name and password, and check the next Automatic Logon function.
3. Click "Log On". If you log on successfully, the logon page is displayed.
4. If you click the CSDN User Logon int
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!
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.