<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 55  文章 - 187  trackbacks - 0
    <2008年9月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    常用鏈接

    留言簿(12)

    隨筆分類

    隨筆檔案

    groovy

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    使用這個(gè)組合,感覺還是很方便靈活的。

    1、將struts2的json插件加入web工程的lib,jsonplugin的下載地址:http://code.google.com/p/jsonplugin/downloads/list

    2、struts.xml添加專為ajax使用的package
    <package name="ajax" extends="json-default">
            
    <action name="ajaxRequest"
                class
    ="org.david.struts2.HelloWorld">
                
    <result type="json"></result>
            
    </action>
        
    </package>

    3、helloworld.jsp
               <SCRIPT type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
            
    <SCRIPT type="text/javascript">
                
    function clickButton()
                
    {    
                    
    var url = 'ajaxRequest.action';
                    
    var params = {
                            name:$('#name').attr('value')
                    }
    ;
                    jQuery.post(url, params, callbackFun, 'json');
                }

                
    function callbackFun(data)
                
    {
                    alert(data.result);//對應(yīng)HelloWorld類的message屬性
                        //獲取數(shù)據(jù)后渲染頁面
                }

            
    </SCRIPT>



           
    <input id="name" type="text">
            
    <input type="button" value="ok" onclick="javascript:clickButton();">

    4、HelloWorld.java
    package org.david.struts2;

    public class HelloWorld {

        
    private String name;
        
    private String result;

        
    // ajax請求參數(shù)賦值
        public void setName(String name) {
            
    this.name = name;
        }


        
    // ajax返回結(jié)果
        public String getResult() {
            
    return result;
        }


        
    public String execute() {
            
    this.result = "Hello! " + this.name + ".";
            
    return "success";
        }


    }
    posted on 2008-09-07 23:07 大衛(wèi) 閱讀(41958) 評論(17)  編輯  收藏 所屬分類: JavaJavaScriptweb

    FeedBack:
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2009-04-11 10:37 starnc
    jQuery.post(url, params, callbackFun, 'json');
    關(guān)于這條語句,我查jquery的api,只有三個(gè)參數(shù)啊,沒有‘json’,這個(gè)參數(shù),請解釋一下,謝謝  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2009-08-31 21:49 ss
    是反回值  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax[未登錄] 2009-10-30 13:48 123
    老大。你的struts2標(biāo)簽?zāi)?  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2010-01-08 15:13 f
    為什么<package name="ajax" extends="json-default">
    的ACTION找不到啊  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2010-01-11 11:19 jazzCat
    請問,返回值data肯定是個(gè)HelloWorld對象么?
    能不能返回自定義的對象呢?  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2010-01-11 11:20 jazzCat
    請問,返回值data肯定是個(gè)HelloWorld對象么?
    能不能返回自定義的對象呢?或返回一個(gè)List?  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2010-01-14 10:00 #tao
    請問callbackFun(data)中的data 是什么啊,我用你的方法可以進(jìn)入到action里面,可是后臺(tái)出錯(cuò)了,能否大蝦這點(diǎn)下
    java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/Object;)Ljava/lang/Object;
    at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:157)
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)

      回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2010-01-15 14:46 gjhohj
    @#tao
    struts 2.0 用json 0.32
    struts 2.1 用 json 0.33-34  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax[未登錄] 2010-04-15 14:09 cc
    json在struts2中的配置只用下plugin嗎。jon-lib.jar這個(gè)包要不要一起加進(jìn)去
    還有一個(gè)json.js這個(gè)要要加
      回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2010-08-18 11:23 葉新華
    樓主 說的很清晰. 贊一個(gè)  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2011-07-08 13:27 jj
    干凈明了
      回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2011-07-25 11:17 guanlin218
    為什么我配置了。一直提示我ajaxRequest.action 這個(gè)找不到。  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax[未登錄] 2012-06-07 18:10 abc
    @starnc
    是不是隨便哪里copy一段來的????  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax[未登錄] 2012-06-07 18:11 abc
    .....  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax[未登錄] 2012-06-07 18:11 abc
    @abc
    adsaf  回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax 2012-08-25 11:46 妞妞
    不用struts的標(biāo)簽也是可以的
      回復(fù)  更多評論
      
    # re: Struts2 + jQuery 實(shí)現(xiàn)ajax[未登錄] 2016-01-16 20:29 1
    @cc
    1  回復(fù)  更多評論
      
    主站蜘蛛池模板: 亚洲国产成人久久综合一区| 亚洲AV女人18毛片水真多| 天天影视色香欲综合免费| 国产成人精品日本亚洲网址| 在线a毛片免费视频观看| 2022免费国产精品福利在线| 一区二区三区亚洲| 国产精品色午夜免费视频| 精品人妻系列无码人妻免费视频 | 日日狠狠久久偷偷色综合免费 | 国产AV无码专区亚洲AV蜜芽| 亚洲欭美日韩颜射在线二| 在线亚洲精品自拍| 18成禁人视频免费网站| 免费国产黄网站在线观看动图| 亚洲av成人无码久久精品| 日本免费一二区在线电影| 可以免费观看的国产视频| 亚洲欧美日韩中文无线码| 国产V亚洲V天堂无码久久久| 麻豆国产VA免费精品高清在线| 男人的天堂网免费网站| 午夜亚洲国产理论片二级港台二级| 久久久无码精品亚洲日韩蜜桃| 日本视频免费在线| www视频在线观看免费| 中文字幕在线观看免费| 亚洲av乱码一区二区三区按摩| 亚洲精品视频免费在线观看| 亚洲一区二区三区在线播放| 卡一卡二卡三在线入口免费| 免费A级毛片无码A∨中文字幕下载| 特级毛片在线大全免费播放| 亚洲综合一区无码精品| 亚洲福利电影在线观看| 亚洲精品tv久久久久久久久| 国产成人免费a在线资源| 无码少妇一区二区浪潮免费| 88av免费观看| 精品亚洲AV无码一区二区三区 | 亚洲中文无码线在线观看|