session过期后,如何让当前页面回到登录页面?? session过期后,如何让当前页面回到登录页面??请帮忙给出具体代码好吗?谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接解这道题我没有答案但是否可以考虑换种思考方式,做个过滤器,在用户发送下一个request的时候,如果该session为空,就返回?(实际上你要控制的是用户的登陆吗?) 是设置了session,过期后,页面就变成了错误的页面,是个问题。所以,但session过期后,回到登录页面,但不知怎么做 session后,session中没有登录的记录,这里forward到登录就ok了吧.难的是怎么记住最后一页在哪里. 新建一个JSP,里面判断session是否过期,如果过期就返回登录页面。然后在你的其它的JSP中用include这个JSP 首先设置session过期的时间,然后在公共模块里判断,如果时间大于session过期时间,则回到登录页面,看看你登录csdn时两秒后自动跳转,和你的是一个道理! 首先在用户身份验证的页面里将登录时的用户信息绑定到session上:(如) //user = request.getParameter("su_id"); //passwd = request.getParameter("su_pwd"); session.setAttribute("UserName", user);然后把下面的JSP内容直接添加或incluse到需要验证的页面中。<%String userName = (String)session.getAttribute("UserName");if(userName == null){ %> <script> alert("请先登录!"); window.top.location.href='../index.htm'; </script> <% }%> 加入验证机制,对url授权session过期就没有访问的权利,就能转到登陆页面 新建一个JSP,里面判断session是否过期,如果过期就返回登录页面。然后在你的其它的JSP中用include这个JSP这个想法是正确的. 用个Bean 不过,还是要建个JSP判断文件 方法1,使用过滤器,判断session过期,就转到某页。方法2,定义一个BaseAction , excute()判断session过期,就转到某页,你所有的Action继承此类,BaseAction{ excute(...){ .... excuteAction(); }}Acion子类覆写excuteAction()就好了。也就是这两个办法。-----------srx(好读书,不求甚解,每有会意,欣然忘食) ( public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws ServletException, IOException { String strReqPage=""; HttpServletRequest req=null; if (request instanceof HttpServletRequest) { req=(HttpServletRequest)request; strReqPage = req.getRequestURI(); //ログインかのを確認する if(strReqPage.indexOf("/faces/jsp/")>0&&strReqPage.indexOf("CO001")<0){ SessionBeanUserInf ssnUsrInf = (SessionBeanUserInf)req.getSession().getAttribute("SessionBeanUserInf"); if(ssnUsrInf==null ||!ssnUsrInf.getLogined()){ if(!(strReqPage.indexOf("ERROR_SG")>0&&req.getParameter("mesgId")!=null)){ //ログイン画面に戻る request.getRequestDispatcher("index.html").forward(request, response); return; } }else if(ssnUsrInf!=null&&ssnUsrInf.getLogined()&&strReqPage.indexOf("CO002")<0){ //アクセスの権限を検証する if((strReqPage.indexOf("TR001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[0])) ||(strReqPage.indexOf("TR002")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[1])) ||(strReqPage.indexOf("AD001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[2])) ||(strReqPage.indexOf("GR001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[3])) ||(strReqPage.indexOf("GR003")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[4])) ||(strReqPage.indexOf("GR005")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[5])) ||(strReqPage.indexOf("temp")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[6]))){ //メーンメニュー画面に戻る request.getRequestDispatcher("CO002.jsp").forward(request, response); return; } } //ApplicationBean をとる Object appObj=req.getSession().getServletContext().getAttribute("ApplicationBean"); if(appObj!=null&& appObj instanceof ApplicationBean &&ssnUsrInf!=null&&ssnUsrInf.getUserId()!=null){ ApplicationBean appBean=(ApplicationBean)appObj; HashMap userMap=appBean.getUserMap(); //ユーザーリストに該当ユーザーを if(userMap!=null&&userMap.containsKey(ssnUsrInf.getUserId())){ if(!userMap.get(ssnUsrInf.getUserId()).equals(ssnUsrInf.getUserIP())){ //ログイン画面に戻る request.getRequestDispatcher("ERROR_SG.jsp?mesgId=ERS010").forward(request, response); } } } } } chain.doFilter(request, response); } 关于jsp传递参数乱码问题 JDBC从数据库中取值 js如何截取传进来的参数???应该蛮简单的吧 displaytag 导出问题 请教: jsp页面潜入java代码中,怎么样获取当前页面参数的值?谢谢! 急需一个含验证码的jsp页面! 求一个JSP的横向菜单! 请教2个小问~,知道的朋友指点一下,谢谢~ JB内为什么“import oracle.jdbc.driver.*;”抱错 关于JSP的try,catch,finally的问题 急聘网站开发人员,在线等 在hibernate中如果我得查询条件中含有中文字符,无法从数据库中查询到应有的信息 为何?请高手指教!!1
但是否可以考虑换种思考方式,
做个过滤器,在用户发送下一个request的时候,如果该session为空,就返回?
(实际上你要控制的是用户的登陆吗?)
然后在你的其它的JSP中用include这个JSP
//user = request.getParameter("su_id");
//passwd = request.getParameter("su_pwd");
session.setAttribute("UserName", user);
然后把下面的JSP内容直接添加或incluse到需要验证的页面中。<%
String userName = (String)session.getAttribute("UserName");
if(userName == null)
{
%>
<script>
alert("请先登录!");
window.top.location.href='../index.htm';
</script>
<%
}
%>
session过期就没有访问的权利,就能转到登陆页面
然后在你的其它的JSP中用include这个JSP这个想法是正确的.
1,使用过滤器,判断session过期,就转到某页。
方法
2,定义一个BaseAction , excute()判断session过期,就转到某页,你所有的Action继承此类,
BaseAction
{
excute(...){
....
excuteAction();
}
}Acion子类覆写excuteAction()就好了。
也就是这两个办法。
-----------srx(好读书,不求甚解,每有会意,欣然忘食) (
throws ServletException, IOException {
String strReqPage="";
HttpServletRequest req=null;
if (request instanceof HttpServletRequest) {
req=(HttpServletRequest)request;
strReqPage = req.getRequestURI();
//ログインかのを確認する if(strReqPage.indexOf("/faces/jsp/")>0&&strReqPage.indexOf("CO001")<0){
SessionBeanUserInf ssnUsrInf = (SessionBeanUserInf)req.getSession().getAttribute("SessionBeanUserInf");
if(ssnUsrInf==null ||!ssnUsrInf.getLogined()){
if(!(strReqPage.indexOf("ERROR_SG")>0&&req.getParameter("mesgId")!=null)){
//ログイン画面に戻る request.getRequestDispatcher("index.html").forward(request, response);
return;
}
}else if(ssnUsrInf!=null&&ssnUsrInf.getLogined()&&strReqPage.indexOf("CO002")<0){
//アクセスの権限を検証する
if((strReqPage.indexOf("TR001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[0]))
||(strReqPage.indexOf("TR002")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[1]))
||(strReqPage.indexOf("AD001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[2]))
||(strReqPage.indexOf("GR001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[3]))
||(strReqPage.indexOf("GR003")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[4]))
||(strReqPage.indexOf("GR005")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[5]))
||(strReqPage.indexOf("temp")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[6]))){
//メーンメニュー画面に戻る request.getRequestDispatcher("CO002.jsp").forward(request, response);
return;
}
}
//ApplicationBean をとる Object appObj=req.getSession().getServletContext().getAttribute("ApplicationBean");
if(appObj!=null&& appObj instanceof ApplicationBean
&&ssnUsrInf!=null&&ssnUsrInf.getUserId()!=null){
ApplicationBean appBean=(ApplicationBean)appObj;
HashMap userMap=appBean.getUserMap();
//ユーザーリストに該当ユーザーを if(userMap!=null&&userMap.containsKey(ssnUsrInf.getUserId())){
if(!userMap.get(ssnUsrInf.getUserId()).equals(ssnUsrInf.getUserIP())){
//ログイン画面に戻る request.getRequestDispatcher("ERROR_SG.jsp?mesgId=ERS010").forward(request, response);
}
}
}
}
}
chain.doFilter(request, response);
}