+ -
当前位置:首页 → 问答吧 → struts2+jquery

struts2+jquery

时间:2009-03-24

来源:互联网

谁能给个struts2+jquery的例子啊。
比如添加一张表单,然后数据通过action后,返回一些反馈信息,
然后再显示在这个表单指定的位置。
谢谢呀

作者: xuganggogo   发布时间: 2009-03-24

jquery 和 struts2  有关系吗??
听你的意思是: jquery 和 struts2 要整合的意思?

作者: wangyongshan   发布时间: 2009-03-24

可以看一下struts2的json插件
http://cwiki.apache.org/S2PLUGINS/json-plugin.html

楼主这类情况我建议使用DWR而不是通过Action来处理

作者: gordianyuan   发布时间: 2009-03-24

呵呵,谢谢关注。
struts2的ajax标签实在不怎么样,就想用jquery整出一套来。
看网络上,还是有用struts2和jquery的,但是实例不多。所以来请求帮助啊 呵呵

作者: xuganggogo   发布时间: 2009-03-24

我知道有一个struts2 jquery plugin
但我没试过不知道效果怎样
有兴趣楼主可以试试
http://code.google.com/p/s2jquery/

作者: gordianyuan   发布时间: 2009-03-25

3q!
好像資源很少

作者: xuganggogo   发布时间: 2009-03-25

噢,我看了一下,那个开发者已经说不再开发那个插件,不要使用

原文如下

Don't use that one--it's not going to be developed and I'll remove it from Google Code. We (where I worked) ended up using straight JavaScript with jQuery.

There were too many issues to make it worth the effort--we were being very accessibility and unobtrusive-JavaScript oriented; a good tag-based  JavaScript solution needs to collect and inject JavaScript in the response outside of the main HTML (as well as a few other games) so it just wasn't a good path for us.

As Wes said there's a new quasi-official (for now) jQuery plugin. Personally I'd skip tag-based solutions altogether, but in some circumstances it might be all you'd need.

作者: gordianyuan   发布时间: 2009-03-25

呵呵,终于做了个简单的例子。
但是ajax只能执行一次。要如何清除缓存啊?

作者: xuganggogo   发布时间: 2009-03-25

ajax有一个cache的属性设置为false即可

作者: gordianyuan   发布时间: 2009-03-25

<script type="text/javascript" src="jquery.js" ></script>    
    <script type="text/javascript" >
        $(document).ready(function(){
            $("#submit").click(function(){
                alert(new Date());
                var t = $("#check").val();
                var time = new Date();
                $.ajax({
                       url :'JsonPlugin.action' ,  //后台处理程序
                       type:'post',    //数据发送方式
                       dataType:'json',   //接受数据格式
                               cache:false,
                       data:{check:t},   //要传递的数据
                       success:update_page  //回传函数(这里是函数名)
                });
            });
        
        //ajax提交
            $("#loading").ajaxStart(function(){
                 $(this).html("<img src=\"loader.gif\"> 正在加载");
              });
                            
            //ajax结束状态
             $("#loading").ajaxStop(function(){
               $(this).hide();
             });
        });
        
        function update_page (json ) { //回传函数实体,参数为XMLhttpRequest.responseText
               var str= "ISBN="+json.ISBN + ",check:" + json.check + ",title="+json.title;
               $("#bookHolder").html(str);
        }
    </script>

我這樣寫了,還是只能执行一次。。费解

作者: xuganggogo   发布时间: 2009-03-25

找到問題所在了。        
  //ajax结束状态
      $("#loading").ajaxStop(function(){
      $(this).hide();
  });
這裡我把這個层隐藏了,所以在怎么提交,也没有显示。

作者: xuganggogo   发布时间: 2009-03-25

找到問題所在了。        
  //ajax结束状态
      $("#loading").ajaxStop(function(){
      $(this).hide();
  });
這裡我把這個层隐藏了,所以在怎么提交,也没有显示。

正确的应该怎么写,我学习下

作者: zhq6648155   发布时间: 2009-03-31

贴一下action的代码吧

作者: yonge   发布时间: 2009-04-15