一、编写Filter拦截器类 

 package com.pv.utils;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; public class RequestFilter implements Filter {
private FilterConfig config;
//实现初始化方法
public void init(FilterConfig config){
this.config = config;
}
public void destroy(){
this.config = null;
} @Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
req.setCharacterEncoding("utf-8");
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession();
//获取客户请求的页面
String url = request.getServletPath();
System.out.println("wangming"+url);
if((!request.getServletPath().equals("/login.jsp"))
&&(!request.getServletPath().equals("/solar.jsp"))
&&(!request.getServletPath().equals("/index.jsp"))){
System.out.println(request.getServletPath());
if(session.getAttribute("username")==null){
session.invalidate();
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
out.println("<script language='javascript' type='text/javascript'>");
out.println("alert('由于你长时间没有操作,导致Session失效!请你重新登录!');top.location.href='" + request.getContextPath() + "/solar.jsp'");
out.println("</script>");
}else{
chain.doFilter(request , response );
}
}else{
chain.doFilter(request , response );
}
}
}

二、在web.xml中配置拦截器  

 <session-config>
<session-timeout>1</session-timeout>
</session-config> <filter>
<filter-name>RequestFilter</filter-name>
<filter-class>com.pv.utils.RequestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

session失效后跳转到登陆页面的更多相关文章

  1. 详解springmvc控制登录用户session失效后跳转登录页面

    springmvc控制登录用户session失效后跳转登录页面,废话不多少了,具体如下: 第一步,配置 web.xml <session-config> <session-timeo ...

  2. MVC 访问IFrame页面Session过期后跳转到登录页面

    Web端开发时,用户登录后往往会通过Session来保存用户信息,Session存放在服务器,当用户长时间不操作的时候,我们会希望服务器保存的Session过期,这个时候,因为Session中的用户信 ...

  3. ajax Session失效如何跳转到登录页面

    在Struts应用中,我们发出的请求都会经过 相应的拦截器进行相关处理,一般都会有一个用户登录拦截(Session失效拦截):一般请求的话,如果Session失效时,我们会跳到登录页面,可是如果我们采 ...

  4. layui弹窗里面 session过期 后跳转到登录页面

    1.在登录页面添加 <script> $(function () { if (top != window) { layer.msg("登录失效", {icon: 5}) ...

  5. 解决ajax 遇到session失效后自动跳转的问题

    在项目中,经常会遇到session失效后,点击任何链接无反应的情况!这样给客户的体验就不是很好,以为是系统出了故障!所以在项目中我们会处理session失效后的跳转问题(一般给用户提示,并跳转后登录页 ...

  6. Session失效后所有Ajax请求跳转登录地址

    当登录的Session失效后,采用ajax请求数据时会没有反应,这时候应该自动跳转到登录页面,让用户重新登录. 全局配置以下可实现 $(function() { $.ajaxSetup({ compl ...

  7. 通过cookies跳过验证码登陆页面,直接访问网站的其它URL

    我每次手动访问去NN网的一家酒店,就不需要登陆,一旦我用脚本打开就会让我登陆,而登陆页面又有验证码,不想识别验证码,所以就想:“通过cookies跳过验证码登陆页面,直接访问网站的其它URL”   转 ...

  8. 关于WordPress登录后跳转到指定页面

    前面在写模版的时候,有朋友要求网站登录后要跳转的到指定的页面.这个从前还真没遇到过.于是就用万能的搜索(很少百度)找了下,方法基本上就是一个,代码如下: <?php    // Fields f ...

  9. shiro控制登陆成功后跳回之前的页面

    登陆之后跳回之前的页面是在做登陆注册模块时遇到的一个需求,也是很有必要的.若用户直接访问登陆页面,那可以控制它直接到首页,但是要用户没有登陆直接访问自己的购物车等需要经过身份认证的页面,或者因为ses ...

随机推荐

  1. Sprint第三个冲刺(第六天)

    一.Sprint介绍 任务进度: 二.Sprint周期 看板: 燃尽图:

  2. C#代码反编译 得到项目可运行源码

    C#代码反编译 得到项目可运行源码 摘自:http://www.cnblogs.com/know/archive/2011/03/15/1985026.html 谈到"C#代码反编译&quo ...

  3. 簡單SQL存儲過程實例

    簡單SQL存儲過程實例 摘自:http://blog.csdn.net/libra6956/article/details/5589173 实例1:只返回单一记录集的存储过程. 银行存款表(bankM ...

  4. sencha gridpanel checkbox 复选框的勾选 以及和单机行冲突

    gridpanel显示checkbox: 添加SelectionModel为Checkbox Selection Model { xtype: 'gridpanel', id: 'Grid1', he ...

  5. 用于dbnull的数据转换。因为用convert.to无法转换dbnull类型

    /// <summary> /// add by wolf /// </summary> public static class ExtendObject { public s ...

  6. flask环境开发搭建

    http://blog.csdn.net/chen_jint/article/details/50550636 ========== 因为笔者开发环境是win7pro,那么就以win7pro为例. p ...

  7. css中inline、block、inline-block的区别

    http://www.cnblogs.com/fxair/archive/2012/07/05/2577280.html display:inline就是将元素显示为块级元素. block元素的特点是 ...

  8. 泛函编程(22)-泛函数据类型-Monoid In Action

    在上一节我们讨论了Monoid的结合性和恒等值的作用以及Monoid如何与串类元素折叠算法相匹配.不过我们只示范了一下基础类型(primitive type)Monoid实例的应用,所以上一节的讨论目 ...

  9. [moka同学代码]PHP初级知识:上传文件源码

    1.目录结构

  10. http 响应码

    一.HTTP码应码响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行. 响应码分五种类型,由它们的第一位数字表示:1.1xx:信息,请求收到,继续处理2.2xx:成功,行为被成功 ...