Logon Timeout: The system prompts you to jump to the logon page (ajax, import, and export). ajax times out.
1. Generally, you can use the filter to verify logon timeout on the page, as shown below:
Package com. lg. filter; import java. io. IOException; import javax. servlet. filter; import javax. servlet. filterChain; import javax. servlet. filterConfig; import javax. servlet. servletException; import javax. servlet. servletRequest; import javax. servlet. servletResponse; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import com. lg. func. myFunc; public class LoginFilter impl Ements Filter {public void destroy () {} public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {HttpServletRequest request1 = (HttpServletRequest) request; httpServletResponse response1 = (HttpServletResponse) response; chain. doFilter (request, response); // allow. Let it go to the next chain or the target resource String url = request1.getServletPath (); System. out. println ("before Demo1 filtering" + url); MyFunc myFunc = new MyFunc (request1, response1); System. out. println ("before Demo1 filtering" + url. startsWith ("/index/"); if (myFunc. checkLogin2 ()&&! Url. startsWith ("/index/") {response1.sendRedirect ("/index_login.html");} System. out. println ("Demo1 filtered");} public void init (FilterConfig arg0) throws ServletException {// TODO Auto-generated method stub System. out. println ("============= init =========" after filtering ");}}
Web. xml configuration
<filter> <filter-name>Demo1Filter</filter-name> <filter-class>com.lg.filter.LoginFilter</filter-class> </filter> <filter-mapping> <filter-name>Demo1Filter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
Ii. ajax submission
Submit page, my page prompts the asyncBox used by the Framework to pop up, you can change it to another jump
$. Ajax ({type: "post", url: ". jsp ", async: false, // synchronize data: {" name ":" fdgh "} success: function (msg) {// checkLogin2 (msg) to determine whether logon times out, if (checkLogin2 (msg) {var obj = eval ('+ msg +'); if (obj. result. indexOf ("suc")>-1) {alert ("successful") ;}else {alert ("failed") ;}}); // whether the logon times out, returns false if the timeout value is exceeded. The function checkLogin2 (msg) {if (msg! = Null & msg. length> 0) {if (msg. indexOf ("DOCTYPE")>-1) {checkLogin (); return false ;}} return true ;} function checkLogin () {if (window. top! = Window. self) {top. asyncbox. alert ('logon time-out, please log on again ', 'hs', function (action) {top. location. href = '/login. jsp ';});} else {asyncbox. alert ('logon time-out, please log on again ', 'hs', function (action) {window. location. href = '/login. jsp ';});}}
Background:
1. Before processing data
if(checkLogin())return;
// Check logon, the session expires, or you have not logged on to the server.
Public boolean checkLogin () throws IOException {
Boolean result = false;
String html = "";
NativeObject u = SessionMng. getCurrentUser (request); // check whether logon times out.
If (u = null ){
Html = "<! Doctype html public '-// W3C // dtd html 4.01 Transitional // en' 'HTTP: // www.w3.org/TR/html4/loose.dtd'> \ n "+
"<Script type = 'text/javascript 'src = '/admin/js/jquery. min. js'> </script> \ n" +
"<Script type = 'text/javascript 'src = '/admin/js/common. js'> </script> \ n" +
"<Script type = 'text/javascript 'src = '/admin/js/dialog/asyncbox. js'> </script> \ n" +
"<Script language = javascript> checkLogin (); </script> \ n ";
Response. getWriter (). println (html );
Result = true;
}
Return result;
}
Iii. Import excel files Asynchronously
Use AjaxUpload. js to import excel
On the frontend submission page, refer to the above section;
Background processing page:
1 if (! IsLogin () {2 response. getWriter (). print ("DOCTYPE"); 3 return; 4} 5 6 // whether to log on to 7 public boolean isLogin () {8 NativeObject u = SessionMng. getCurrentUser (request); 9 if (u! = Null) {10 return true; 11} else {12 return false; 13} 14}
4. Use window. open to export an excel file
Same background as 2
Frontend export page
Function export_excel () {$. ajax ({type: "post", url: "/admin/inc/checkLogin. jsp ", async: false, // synchronize success: function (msg) {if (checkLogin2 (msg) {window. open ("perfm_excel.jsp? "+ $ ('# Form1'). serialize ());}}});
Login. jsp
<% @ Page contentType = "text/html; charset = UTF-8 "%> <% // ========================== current Login User Information ==== ============================================================== if (checkLogin ()) return; %>