如何在jsp中刷新时防止重新执行动作 [英] how to prevent reexecute action when refresh in jsp

查看:121
本文介绍了如何在jsp中刷新时防止重新执行动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jsp编写应用程序,并且遇到这样的问题,即浏览器总是会缓存我执行的URL,因此当用户刷新页面时,该操作将再次执行。
例如:
> transfer;
如果我点击链接,之后刷新页面,这个动作会再次执行
我也知道,我需要用来避免这个问题,但它真的不方便。

任何一个有更好的解决方案?
任何建议将不胜感激。
在此先感谢。

解决方案

此解决方案适用于Internet Explorer。

 < script type =text / javascript> 
document.onkeydown = function(){
if(window.event&& window .event.keyCode == 116){//捕获并重新映射F5
window.event.keyCode = 505;
}
if(window.event&& window.event.keyCode == 505){//为F5添加新操作
返回false; //必须返回false或浏览器将刷新


$ lt; / script>


I use jsp to write a application, and i encounter such a problem, that the browser will always cache the URL i execute, so when user refresh the page, the action will be execute again. for example: ">transfer; if i clicked the link, and after that , i refresh the page, this action will be execute again. I also know, that i need to use to avoid this problem, but it is really not convenient.

Any one have a better solution ? Any suggestions will be appreciated. Thanks in advance.

解决方案

This solution works with Internet Explorer.

<script type="text/javascript">
  document.onkeydown = function(){
     if(window.event && window.event.keyCode == 116){ // Capture and remap F5  
         window.event.keyCode = 505;  
     }
     if(window.event && window.event.keyCode == 505){ // New action for F5  
         return false;  // Must return false or the browser will refresh anyway  
    }  
}
</script>

这篇关于如何在jsp中刷新时防止重新执行动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆