登錄超時(shí)給出提示跳到登錄頁(yè)面(ajax、導(dǎo)入、導(dǎo)出)
一、一般頁(yè)面登錄超時(shí)驗(yàn)證,可以用過(guò)濾器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);//放行。讓其走到下個(gè)鏈或目標(biāo)資源中 String url=request1.getServletPath(); System.out.println("Demo1過(guò)濾前"+url); MyFunc myFunc = new MyFunc(request1,response1); System.out.println("Demo1過(guò)濾前"+url.startsWith("/index/")); if(myFunc.checkLogin2()&&!url.startsWith("/index/")){ response1.sendRedirect("/index_login.html"); } System.out.println("Demo1過(guò)濾后"); } public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub System.out.println("===========init========過(guò)濾后"); } }
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提交
提交頁(yè)面,我的頁(yè)面提示彈出框架用的asyncBox,可以改成其他的跳轉(zhuǎn)
$.ajax({ type: "post", url:"a.jsp", async:false,//同步 data:{"name":"fdgh"} success:function(msg){ //checkLogin2(msg)判斷是否登錄超時(shí),超時(shí)返回false,跳到登錄頁(yè)面 if(checkLogin2(msg)){ var obj=eval('('+msg+')'); if(obj.result.indexOf("suc")>-1){ alert("成功"); }else{ alert("失敗"); } } }); //是否登錄超時(shí),超時(shí)返回false,跳到登錄頁(yè)面 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('登錄超時(shí),請(qǐng)重新登錄', '提示', function(action){ top.location.href='/login.jsp'; }); }else{ asyncbox.alert('登錄超時(shí),請(qǐng)重新登錄', '提示', function(action){ window.location.href='/login.jsp'; }); } }
后臺(tái):
1.處理數(shù)據(jù)前
if(checkLogin())return; //檢查登錄,session過(guò)期,或者未登錄,自動(dòng)跳轉(zhuǎn) public boolean checkLogin() throws IOException{ boolean result = false; String html = ""; NativeObject u = SessionMng.getCurrentUser(request);//檢驗(yàn)是否登錄超時(shí) 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; }
三、異步導(dǎo)入excel
用AjaxUpload.js導(dǎo)入excel功能
前端提交頁(yè)面參考上面的;
后臺(tái)處理頁(yè)面:
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導(dǎo)出excel文件
后臺(tái)同二
前端導(dǎo)出頁(yè)面
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"%> <% //========================當(dāng)前登陸用戶信息======================================== if(checkLogin())return; %>
以上內(nèi)容給大家介紹了登錄超時(shí)給出提示跳到登錄頁(yè)面(ajax、導(dǎo)入、導(dǎo)出)的相關(guān)知識(shí),希望對(duì)大家有所幫助!
- 一款經(jīng)典的ajax登錄頁(yè)面 后臺(tái)asp.net
- Ajax異步方式實(shí)現(xiàn)登錄與驗(yàn)證
- ajax 實(shí)現(xiàn)微信網(wǎng)頁(yè)授權(quán)登錄的方法
- ajax實(shí)現(xiàn)登錄功能
- Ajax實(shí)現(xiàn)帶有驗(yàn)證碼的局部刷新登錄界面
- div彈出層的ajax登錄(Jquery版+c#)
- Ajax Session失效跳轉(zhuǎn)登錄頁(yè)面的方法
- ajax編寫簡(jiǎn)單的登錄頁(yè)面
- Ajax實(shí)現(xiàn)漂亮、安全的登錄界面
- Ajax實(shí)現(xiàn)登錄案例
相關(guān)文章
Ajax跨域問(wèn)題及解決方案(jsonp,cors)
遠(yuǎn)程服務(wù)器上設(shè)法動(dòng)態(tài)的把數(shù)據(jù)裝進(jìn)js格式的文本代碼段中,供客戶端調(diào)用和進(jìn)一步處理。這篇文章主要介紹了ajax跨域問(wèn)題解決方案(jsonp,cors) ,需要的朋友可以參考下2019-06-06JQuery的ajax的用法在asp中使用$.ajax()實(shí)現(xiàn)
ajax的出現(xiàn)解決了很多的疑難問(wèn)題,同時(shí)帶來(lái)了很多的方便,本文講述一下JQuery的ajax的用法在asp中使用$.ajax()來(lái)表示,感興趣的朋友可以了解下,或許本文對(duì)你有所幫助2013-01-01Ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)實(shí)例代碼
這篇文章主要介紹了Ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03Ajax 框架之SSM整合框架實(shí)現(xiàn)ajax校驗(yàn)
這篇文章主要介紹了Ajax 框架之SSM整合框架實(shí)現(xiàn)ajax校驗(yàn),需要的朋友可以參考下2017-04-04Ajax登陸使用Spring Security緩存跳轉(zhuǎn)到登陸前的鏈接
這篇文章主要介紹了Ajax登陸使用Spring Security緩存跳轉(zhuǎn)到登陸前的鏈接,需要的朋友可以參考下2019-04-04無(wú)框架 Ajax分頁(yè)(原創(chuàng))
最近想做一個(gè)Ajax的功能,網(wǎng)上一搜幾乎全是基于某某框架的Ajax分頁(yè),要么需給頁(yè)面加上<scriptManager></scriptManager>,要么需引入某dll,要么需使用類似于jquery的框架。2009-08-08Ajax獲取回調(diào)函數(shù)無(wú)法賦值給全局變量的問(wèn)題
這篇文章主要介紹了Ajax獲取回調(diào)函數(shù)無(wú)法賦值給全局變量的問(wèn)題,需要的朋友可以參考下2018-06-06AJAX實(shí)現(xiàn)仿Google Suggest效果
AJAX實(shí)現(xiàn)仿Google Suggest效果...2007-07-07$.ajax傳JSON數(shù)據(jù)到后臺(tái)出現(xiàn)報(bào)錯(cuò)問(wèn)題解決
$.ajax傳JSON數(shù)據(jù)到后臺(tái)時(shí)總會(huì)出現(xiàn)一些錯(cuò)誤,本文整理了一些注意事項(xiàng),感興趣的朋友可以參考下2014-01-01談?wù)凙jax原理實(shí)現(xiàn)過(guò)程
Asynchronous javascript and xml(ajax),實(shí)現(xiàn)了客戶端與服務(wù)器進(jìn)行數(shù)據(jù)交流過(guò)程。使用技術(shù)的好處是:不用頁(yè)面刷新,并且在等待頁(yè)面?zhèn)鬏敂?shù)據(jù)的同時(shí)可以進(jìn)行其他操作2015-11-11