登入逾時給出提示跳到登入頁面(ajax、匯入、匯出)_AJAX相關

來源:互聯網
上載者:User

一、一般頁面登入逾時驗證,可以用過濾器filter,如下:

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, ServletResponse response,FilterChain chain) throws ServletException, IOException {HttpServletRequest request1=(HttpServletRequest)request;HttpServletResponse response1=(HttpServletResponse)response;chain.doFilter(request, response);//允許存取。讓其走到下個鏈或目標資源中String url=request1.getServletPath();System.out.println("Demo1過濾前"+url);MyFunc myFunc = new MyFunc(request1,response1);System.out.println("Demo1過濾前"+url.startsWith("/index/"));if(myFunc.checkLogin2()&&!url.startsWith("/index/")){response1.sendRedirect("/index_login.html");}System.out.println("Demo1過濾後");}public void init(FilterConfig arg0) throws ServletException {// TODO Auto-generated method stubSystem.out.println("===========init========過濾後");}}

web.xml配置

<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> 

二、ajax提交

提交頁面,我的頁面提示彈出架構用的asyncBox,可以改成其他的跳轉

$.ajax({type: "post",url:"a.jsp",async:false,//同步data:{"name":"fdgh"}success:function(msg){//checkLogin2(msg)判斷是否登入逾時,逾時返回false,跳到登入頁面if(checkLogin2(msg)){var obj=eval('('+msg+')');if(obj.result.indexOf("suc")>-1){alert("成功");}else{alert("失敗");}}});//是否登入逾時,逾時返回false,跳到登入頁面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('登入逾時,請重新登入', '提示', function(action){ top.location.href='/login.jsp';}); }else{asyncbox.alert('登入逾時,請重新登入', '提示', function(action){window.location.href='/login.jsp';}); }}

後台:

1.處理資料前

if(checkLogin())return; //檢查登入,session到期,或者未登入,自動跳轉public boolean checkLogin() throws IOException{boolean result = false;String html = "";NativeObject u = SessionMng.getCurrentUser(request);//檢驗是否登入逾時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;}

三、非同步匯入excel

用AjaxUpload.js匯入excel功能

前端提交頁面參考上面的;

幕後處理頁面:

if(!isLogin()){response.getWriter().print("DOCTYPE");return ;}//是否登入public boolean isLogin(){NativeObject u = SessionMng.getCurrentUser(request);if (u != null){return true;}else{return false;}}

四。用window.open匯出excel檔案

後台同二

前端匯出頁面

function export_excel(){ $.ajax({type: "post",url:"/admin/inc/checkLogin.jsp",async:false,//同步success:function(msg){if(checkLogin2(msg)){window.open("perfm_excel.jsp?"+$('#Form1').serialize());}}}); login.jsp<%@ page contentType="text/html; charset=utf-8"%><%//========================當前登陸使用者資訊========================================if(checkLogin())return;%> 

以上內容給大家介紹了登入逾時給出提示跳到登入頁面(ajax、匯入、匯出)的相關知識,希望對大家有所協助!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.