登陆过滤 Session失效,跳转回login页面
来源:互联网 发布:骑砍战团 for mac下载 编辑:程序博客网 时间:2024/04/30 07:06
登陆过滤类;
public class LoginFilter implements Filter {
private FilterConfig config;
private String logon_page;
private String home_page;
public void destroy() {
config = null;
}
public void init(FilterConfig filterconfig) throws ServletException {
// 从部署描述符中获取登录页面和首页的URI
config = filterconfig;
logon_page = filterconfig.getInitParameter("LOGON_URI");
home_page = filterconfig.getInitParameter("HOME_URI");
if(null == logon_page || null == home_page) {
throw new ServletException("没有找到登录页面或主页");
}
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
Login login =(Login) req.getSession().getAttribute("login");
String request_uri = req.getRequestURI().toUpperCase(); //得到用户请求的URI
System.out.println(request_uri);
String ctxPath = req.getContextPath(); //得到web应用程序的上下文路径
String uri = request_uri.substring(ctxPath.length()); //去除上下文路径,得到剩余部分的路径
try {
if(!request_uri.equals("/LEAMEDCALL/LOGIN") && login == null) {
System.out.println("***********************************");
rsp.sendRedirect(home_page+logon_page);
// PrintWriter out = rsp.getWriter();
// out.println("<script type='text/javascript'>window.parent.location='"+home_page+logon_page+"'</script>");
System.out.println(home_page+logon_page);
return;
}
else {
chain.doFilter(request, response);
}
} catch (IOException e) {
} catch (ServletException e1) {
}
}
}
web.xml配置
<filter>
<filter-name>loginfilter</filter-name>
<filter-class>filter.LoginFilter</filter-class>
<init-param>
<param-name>LOGON_URI</param-name>
<param-value>/login.jsp</param-value>
</init-param>
<init-param>
<param-name>HOME_URI</param-name>
<param-value>/LeamedCall</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>loginfilter</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
如果使用frame框架,跳到单独的页面login.jsp
在login.jsp页面加上
<script type="text/javascript">
if(top!=self){
if(top.location != self.location)
top.location=self.location;
}
</script>
- 登陆过滤 Session失效,跳转回login页面
- iframe session 失效 跳转至登陆页面
- session失效后跳转到登陆页面
- session失效后跳转到登陆页面
- 配置struts2过滤器 session失效跳转到登陆页面
- session失效后,跳转到登陆页面的解决办法
- 登陆页面跳转、页面过滤验证(filter过滤,session传值,获取java路径)
- 关于session失效如何跳转到login页中的问题
- session失效对自动跳转登录页面
- iframe session失效,跳转登录页面
- login控件的登陆成功后跳转到哪个页面
- session失效后ajax请求跳转到登陆页
- session失效时 中间等待页面 跳转至登录页面
- 使用iframe时session失效时登陆页面跳到最顶层
- 拦截器针对ajax Session失效跳转到登录页面
- session失效,过滤器中frame框架页面跳转
- ajax Session失效如何跳转到登录页面
- springmvc控制登录用户session失效后跳转登录页面
- IE8 不支持CSS word-wrap属性
- 策划入门(五):开始绘制系统的结构流程
- socket函数手册
- gff
- 信息加密算法
- 登陆过滤 Session失效,跳转回login页面
- 策划入门(六):一点一点的把模块变成现实
- 策划入门(七):如何分配工作任务
- 策划入门(八):开发中的沟通与协调
- 结构体长度的计算
- 策划入门(九):测试方案的产生
- 关于线性表的C程序,语法问题?不会吧
- 游戏地图技术Terrain Splatting
- 用Visual Studio打包(转)