Login timeout gives tips for jumping to the login page (Ajax, import, export) _ajax related

Source: Internet
Author: User

One or one-page logon timeout verification, filter filter can be used, as follows:

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 implements filter{public void Destroy () {} public void Dofilter (ServletRequest request, Servlet Response Response, Filterchain chain) throws Servletexception, IOException {httpservletrequest request1= (
HttpServletRequest) Request;
HttpServletResponse response1= (httpservletresponse) response; Chain.dofilter (request, response);/release.
Let it go to the next chain or target resource String url=request1.getservletpath ();
System.out.println ("Demo1 filter Before" +url);
MyFunc MyFunc = new MyFunc (REQUEST1,RESPONSE1);
System.out.println ("Demo1 filter Before" +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 filtration "); }
}

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>

Second, the AJAX submission

Submit the page, my page prompts pop-up frame with the Asyncbox, can be changed to other jumps

$.ajax ({
type: "Post",
URL: "a.jsp",
async:false,//sync
data:{"name": "Fdgh"}
success:function ( msg) {
//checklogin2 (msg) determines whether a login timeout, returns false, jumps to the login page
if (checkLogin2 (msg)) {
var obj=eval (' (' +msg+ ') ');
if (Obj.result.indexOf ("suc") >-1) {
alert ("Success");
} else{
alert ("Failed");}}
);
Login timeout, timeout return false, skip to login page
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 (' Login timeout, login again ', ' Prompt ', function ( Action) { 
top.location.href= '/login.jsp ';
}); 
else{
asyncbox.alert (' login timeout, please login ', ' Prompt ', function (action) {
window.location.href= '/login.jsp ';
} 
}
}

Background:

1. Before processing data

if (Checklogin ()) return; 
Check login, session expired, or not logged in, automatic jump public
Boolean Checklogin () throws ioexception{
Boolean result = false;
String html = "";
NativeObject u = sessionmng.getcurrentuser (Request)//Verify login timeout
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= ' 
Js/dialog/asyncbox.js ' ></script>\n "+ 
" <script language=javascript>checklogin (); </script >\n ";
Response.getwriter (). println (HTML); 
result = true;
}
return result;
}

Three, import Excel asynchronously

Import Excel features with Ajaxupload.js

Front-End submission page reference above;

Background processing page:

if (!islogin ()) {
response.getwriter (). Print ("DOCTYPE");
return;
}
Log on to Public
Boolean islogin () {
nativeobject u = sessionmng.getcurrentuser (request);
if (U!= null) {return
true;
} else{return
false;
}

Four. Exporting Excel files with window.open

Backstage with two

Front End Export Page

function Export_excel () { 
$.ajax ({
type: Post),
URL: "/admin/inc/checklogin.jsp",
async:false ,//Synchronous
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;

The above content to introduce you to the login timeout to jump to the login page (Ajax, import, export) related knowledge, I hope to help you!

Related Article

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.