前一段时间做了一个小网站,本来想用fiter过滤后台登录,可是,当你给一个flag时,它实际还是存储在session中,这样的话,在我把url直接跨过框架指向一个新增或者其它后台页面时,只要session中登录过保存的值,直接关闭后,还是没有清除,因此,有人下次不用登录就可以指到这个地址。下面我介绍一下自己用的解决方案。
一、新建一个.js文件,将以下代码保存:
function window.onUnload()
{
var newWindow;
if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
{ newWindow=window.open('destorys.jsp','网页名称','width=0,height=0,top=4000,left=4000');//新窗口将在视区之外打开 newWindow.opener=null; sleep(5000); newWindow.close();//新窗口关闭 }
}
function sleep(milisecond)
{ var currentDate,beginDate=new Date(); var beginHour,beginMinute,beginSecond,beginMs; var hourGaps,minuteGaps,secondGaps,msGaps,gaps; beginHour=beginDate.getHours(); beginMinute=beginDate.getMinutes(); beginSecond=beginDate.getSeconds(); beginMs=beginDate.getMilliseconds(); do { currentDate=new Date(); hourGaps=currentDate.getHours() - beginHour; minuteGaps=currentDate.getMinutes() - beginMinute; secondGaps=currentDate.getSeconds() - beginSecond; msGaps=currentDate.getMilliseconds() - beginMs; if(hourGaps<0) hourGaps+=24; //考虑进时进分进秒的特殊情况 gaps=hourGaps*3600+ minuteGaps*60+ secondGaps; gaps=gaps*1000+msGaps; }while(gaps<milisecond); }
其中红色部分为你指向清除session的JSp页面。
如下:
<%@ page contentType="text/html; charset=GBK" %> <%@ page language="java" import="java.lang.*"%> <jsp:useBean id="login" scope="page" class="com.util.Login"/> <% session.removeAttribute("username"); session.removeAttribute("userid"); session.removeAttribute("power"); session.removeAttribute("flag"); %>
这样,在每个后台页面引用一个这个JS,就可以实现了。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)