Login filter session failure, jump back to the login page

Source: Internet
Author: User

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 descriptor
Config = filterconfig;
Logon_page = filterconfig. getinitparameter ("logon_uri ");
Home_page = filterconfig. getinitparameter ("home_uri ");

If (null = logon_page | null = home_page ){
Throw new servletexception ("Logon page or homepage not found ");
}
}

@ Override
Public void dofilter (servletrequest request, servletresponse response,
Filterchain chain) throws ioexception, servletexception {
Httpservletrequest Req = (httpservletrequest) request;
Httpservletresponse RSp = (httpservletresponse) response;


Login Login = (LOGIN) Req. getsession (). getattribute ("login ");
String request_uri = Req. getrequesturi (). touppercase (); // obtain the URI requested by the user
System. Out. println (request_uri );
String ctxpath = Req. getcontextpath (); // obtain the context path of the Web application.
String uri = request_uri.substring (ctxpath. Length (); // remove the context path and obtain the path of the remaining part.
Try {

If (! Request_uri.equals ("/leamedcall/login") & login = NULL ){
System. out. println ("***********************************");
RSP. sendredirect (home_page + logon_page );
// Printwriter out = RSP. getwriter ();
// Out. println ("<SCRIPT type = 'text/JavaScript '> window. Parent. Location ='" + home_page + logon_page + "'</SCRIPT> ");
System. Out. println (home_page + logon_page );
Return;
}
Else {
Chain. dofilter (request, response );
}
} Catch (ioexception e ){

} Catch (servletexception E1 ){
}
}

}

 

 

Web. xml configuration

 

<Filter>
<Filter-Name> loginfilter </filter-Name>
<Filter-class> filter. loginfilter </filter-class>
<Init-param>
<Param-Name> logon_uri </param-Name>
<Param-value>/login. jsp </param-value>
</Init-param>
<Init-param>
<Param-Name> home_uri </param-Name>
<Param-value>/leamedcall </param-value>
</Init-param>
</Filter>

<Filter-mapping>
<Filter-Name> loginfilter </filter-Name>
<URL-pattern>/admin/* </url-pattern>
</Filter-mapping>

 

 

 

If the frame framework is used, jump to the separate page login. jsp

Add

<SCRIPT type = "text/JavaScript">
If (top! = Self ){
If (top. location! = Self. Location)
Top. Location = self. location;
}
</SCRIPT>

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.