frame页面跳转和信息提示页面

在web应用中经常需要判断用户是否已经登录,如果没有登录,那么跳转到登录页面。一般我们在后台页面中都会使用frame来划分功能区。这种方法比较实用,但是随之而来就有一个小问题,就是当用户session超时之后,当用户再在后台进行操作时,我们需要重新让用户登录。一般我会选择使用一个Filter来控制用户的访问权限,当用户没有登录的时候重定向到login.jsp。那么我们可以直接使用request.sendRedirect()方法来实现。但是由于是在frame中,所以这种方式会将login.jsp显示在当前的frame中,这并不是我们想要的效果。sendRedirect放方法中并没有能<A>中的target属性。这里我们可以采用javascript来实现这一功能。

PrintWriter out =resp.getWriter();

out.write("<html>");

out.write("<script>");

out.write("window.open ('login.jsp','_top')");

out.write("</script>");

out.write("</html>");

return;

当然,如果浏览器禁用了javascript,那么这种方法就没用了。不过有多少人没事将javascript禁用调用呢。如果有更好的方案(不使用js),麻烦告知我一下..

还有一个问题就是,当用户登录失败或者操作执行之后总是需要给出一些提示信息吧。如果总是使用js弹窗来做提示的话,用户体验不好。最好还是专门做一个提示页面,当需要显示提示信息的时候,我们可以呈现该页面,并将一些参数传递过来,比如提示内容,要调转的页面等。在使用struts2时,我不太喜欢使用自带的一些提示功能(也不喜欢用它的标签),小的网站应用根本不用考虑国际化之类的问题,直接把提示硬编码在代码中效率更高,谁没事三天两头的去修改代码…

message.jsp

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3.     String path = request.getContextPath()  
  4.             + request.getAttribute("url");  
  5. %>  
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  7. <html>  
  8.     <head>  
  9.   
  10.         <title>提示信息</title>  
  11.         <meta http-equiv="pragma" content="no-cache">  
  12.         <meta http-equiv="cache-control" content="no-cache">  
  13.         <meta http-equiv="expires" content="0">  
  14.         <meta http-equiv="Refresh" content="4; url=<%=path%>" />  
  15.     </head>  
  16.   
  17.     <body>  
  18.         <table border="0" align="center" cellpadding="5" cellspacing="1"  
  19.             style="font-size: 14px; color: #333333; margin-top: 100px; background: #70afd3">  
  20.             <tr style="color: #FFFFFF">  
  21.                 <th>  
  22.                     提示信息  
  23.                 </th>  
  24.             </tr>  
  25.             <tr>  
  26.                 <td height="100" style="font-size: 12px; background: #FFFFFF">  
  27.                     <div style="font-size: 14px; font-weight: bold; margin: 10px;">  
  28.                         ${message}  
  29.                     </div>  
  30.                     <div style="margin: 10px;">  
  31.                         系统将在   
  32.                         <span id="countDownSec" style="color: blue; font-weight: bold"></span> 秒后自动跳转,如果不想等待,直接  
  33.                         <a href=<%=path%> style="color: #069;">点击这里</a>  
  34.                     </div>  
  35.                 </td>  
  36.             </tr>  
  37.         </table>  
  38. <script language="javascript" type="text/javascript">  
  39. var countDown = function(timer,eleId,interType){  
  40.     document.getElementById(eleId).innerHTML = timer;  
  41.     var interval = interType=='s'?1000:(interType=='m'?1000*60:1000*60*60);  
  42.     window.setInterval(function(){  
  43.         timer--;  
  44.         if (timer > 0) {  
  45.             document.getElementById(eleId).innerHTML = timer;  
  46.         }  
  47.     },interval);  
  48. };  
  49.   
  50. countDown(4,'countDownSec','s');  
  51.   
  52. </script>  
  53.     </body>  
  54. </html>  
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath() + request.getAttribute("url"); %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>提示信息</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="Refresh" content="4; url=<%=path%>" /> </head> <body> <table border="0" align="center" cellpadding="5" cellspacing="1" style="font-size: 14px; color: #333333; margin-top: 100px; background: #70afd3"> <tr style="color: #FFFFFF"> <th> 提示信息 </th> </tr> <tr> <td height="100" style="font-size: 12px; background: #FFFFFF"> <div style="font-size: 14px; font-weight: bold; margin: 10px;"> ${message} </div> <div style="margin: 10px;"> 系统将在  <span id="countDownSec" style="color: blue; font-weight: bold"></span> 秒后自动跳转,如果不想等待,直接 <a href=<%=path%> style="color: #069;">点击这里</a> </div> </td> </tr> </table> <script language="javascript" type="text/javascript"> var countDown = function(timer,eleId,interType){ document.getElementById(eleId).innerHTML = timer; var interval = interType=='s'?1000:(interType=='m'?1000*60:1000*60*60); window.setInterval(function(){ timer--; if (timer > 0) { document.getElementById(eleId).innerHTML = timer; } },interval); }; countDown(4,'countDownSec','s'); </script> </body> </html>

Action呈现提示页面:

setMessage("登录失败:用户名或密码不正确!","/admin/login.jsp");

return MESSAGE;

效果图:

以上是小弟个人看法,如有不妥之处还望前辈指正!


转载于:https://my.oschina.net/u/1427708/blog/710681

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值