首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp怎么实现postback

2013-11-29 
jsp如何实现postback项目的user网络条件比较恶劣,经常会出现等待页面回发情况,此时要是user多次点击处于回

jsp如何实现postback
项目的user网络条件比较恶劣,经常会出现等待页面回发情况,此时要是user多次点击处于回发状态的Button,势必带来一些问题,特别是与数据库交互的时候。为此,找了些资料,写了些简单的方法来避免这些问题。

具体的情况是,实现点击1个Button,立刻disable该button,不让user点击第2次,等Button服务端处理好之后,再将Button变为可用。在用户网络条件恶劣情况下,阻止多次Request向服务端传送重复数据。

一. 在不引用AJAX的情况下,需要手动调用Button的postback。详情在http://blog.csdn.net/aboutblog/archive/2006/09/27/1293926.aspx 和 http://www.cnblogs.com/jackhuclan/archive/2008/08/05/1261027.html 里。里面有关于PostBack的机制和如何注册服务端控件的postback。

-----------------------我是分割线-------------------------------
上面是在http://www.cnblogs.com/sothicor/articles/1288484.html看到的。我查到postback是asp.net的,我想问jsp里面怎么实现这个功能。
页面上有一列单选按钮,我选中一个,点提交按钮,生成一个pdf文件,然后在等文件生成的过程中该按钮变灰,这个用disabled=true就行了,但是如何在生成pdf文件后将按钮变成亮的。因为这个生成pdf的貌似是个异步的。

[解决办法]
用ajax请求,请求成功后,回调函数里将disabled=false。

[解决办法]
ajax请求如果是你的场景的话直接将ajax的异步设置成false。这样在后台没有结束之前,页面上所有的都点不了!


$.ajax({
                        type: "POST",
                        url:"/CPS/loginAction.do",
                        data:encodeURI($('#loginForm').serialize()),
                        dataType:"json",
                        async: false,
                 error: function(request) {
                 alert("由于网络原因请求失败");
                 },
                 success: function(data) {
                         if(data.loginState == "failed"){
                                 alert("用户名或密码不正确,登陆失败");
                         }else{
                                 window.location.replace("index.jsp");
                         }
                                
                 }
                });

[解决办法]
引用:
Quote: 引用:

我去这代码和字体编辑器混合使用有问题啊!
$.ajax({
                        type: "POST",
                        url:"/CPS/loginAction.do",
                        data:encodeURI($('#loginForm').serialize()),
                        dataType:"json",
                        async: false,
                 error: function(request) {
                 alert("由于网络原因请求失败");
                 },
                 success: function(data) {
                         if(data.loginState == "failed"){


                                 alert("用户名或密码不正确,登陆失败");
                         }else{
                                 window.location.replace("index.jsp");
                         }
                                 
                 }
                });


版主好,能看下这个链接么?http://www.cnblogs.com/sharpxiajun/archive/2012/04/26/2471990.html
里面说“asyn:false,这个参数我设置过,效果一样的,应该说XMLHttpRequest是重新开启了个http连接,我们的ajax函数只是封装请求信息,并且调用它,因为是内部独立的http链接,XMLHttpRequest是独立运行的,和原来的ajax函数无关”
我自己还没熟悉ajax怎么写,所以现在还不能改写我的代码成ajax。


博客乱扯吧?那个参数就是锁定浏览器不让操作的!
还是看官方的解释:


async (default: true)
Type: Boolean
By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().

http://api.jquery.com/jQuery.ajax/

热点排行