Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > ajax

登录超时给出提示跳到登录页面(ajax、导入、导出)

来源:中文源码网    浏览:128 次    日期:2024-05-10 16:11:19
【下载文档:  登录超时给出提示跳到登录页面(ajax、导入、导出).txt 】


登录超时给出提示跳到登录页面(ajax、导入、导出)
一、一般页面登录超时验证,可以用过滤器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 stub
System.out.println("===========init========过滤后");
}
}
web.xml配置

Demo1Filter
com.lg.filter.LoginFilter


Demo1Filter
*.jsp

二、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 = "\n" +
"\n" +
"\n" +
"\n" +
"\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、导入、导出)的相关知识,希望对大家有所帮助!

相关内容