主頁 > 知識(shí)庫 > 登錄超時(shí)給出提示跳到登錄頁面(ajax、導(dǎo)入、導(dǎo)出)

登錄超時(shí)給出提示跳到登錄頁面(ajax、導(dǎo)入、導(dǎo)出)

熱門標(biāo)簽:Mysql連接數(shù)設(shè)置 銀行業(yè)務(wù) 團(tuán)購網(wǎng)站 Linux服務(wù)器 科大訊飛語音識(shí)別系統(tǒng) 電子圍欄 服務(wù)器配置 阿里云

一、一般頁面登錄超時(shí)驗(yàn)證,可以用過濾器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過濾前"+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 stub
System.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,可以改成其他的跳轉(zhuǎn)

$.ajax({
type: "post",
url:"a.jsp",
async:false,//同步
data:{"name":"fdgh"}
success:function(msg){
//checkLogin2(msg)判斷是否登錄超時(shí),超時(shí)返回false,跳到登錄頁面
if(checkLogin2(msg)){
var obj=eval('('+msg+')');
if(obj.result.indexOf("suc")>-1){
alert("成功");
}else{
alert("失敗");
}
}
});
//是否登錄超時(shí),超時(shí)返回false,跳到登錄頁面
function checkLogin2(msg){
if(msg!=nullmsg.length>0){
if(msg.indexOf("DOCTYPE")>-1){
checkLogin();
return false;
}
}
return true;
}
function checkLogin(){
if(window.top != window.self){
top.asyncbox.alert('登錄超時(shí),請重新登錄', '提示', function(action){ 
top.location.href='/login.jsp';
}); 
}else{
asyncbox.alert('登錄超時(shí),請重新登錄', '提示', function(action){
window.location.href='/login.jsp';
}); 
}
}

后臺(tái):

1.處理數(shù)據(jù)前

if(checkLogin())return; 
//檢查登錄,session過期,或者未登錄,自動(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功能

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

后臺(tái)處理頁面:

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)出頁面

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í)給出提示跳到登錄頁面(ajax、導(dǎo)入、導(dǎo)出)的相關(guān)知識(shí),希望對大家有所幫助!

您可能感興趣的文章:
  • 一款經(jīng)典的ajax登錄頁面 后臺(tái)asp.net
  • Ajax異步方式實(shí)現(xiàn)登錄與驗(yàn)證
  • ajax 實(shí)現(xiàn)微信網(wǎng)頁授權(quán)登錄的方法
  • ajax實(shí)現(xiàn)登錄功能
  • Ajax實(shí)現(xiàn)帶有驗(yàn)證碼的局部刷新登錄界面
  • div彈出層的ajax登錄(Jquery版+c#)
  • Ajax Session失效跳轉(zhuǎn)登錄頁面的方法
  • ajax編寫簡單的登錄頁面
  • Ajax實(shí)現(xiàn)漂亮、安全的登錄界面
  • Ajax實(shí)現(xiàn)登錄案例

標(biāo)簽:萍鄉(xiāng) 衢州 衡水 大理 廣元 蚌埠 江蘇 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《登錄超時(shí)給出提示跳到登錄頁面(ajax、導(dǎo)入、導(dǎo)出)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266