<legend id='aK5Ue'><style id='aK5Ue'><dir id='aK5Ue'><q id='aK5Ue'></q></dir></style></legend>

  • <i id='aK5Ue'><tr id='aK5Ue'><dt id='aK5Ue'><q id='aK5Ue'><span id='aK5Ue'><b id='aK5Ue'><form id='aK5Ue'><ins id='aK5Ue'></ins><ul id='aK5Ue'></ul><sub id='aK5Ue'></sub></form><legend id='aK5Ue'></legend><bdo id='aK5Ue'><pre id='aK5Ue'><center id='aK5Ue'></center></pre></bdo></b><th id='aK5Ue'></th></span></q></dt></tr></i><div id='aK5Ue'><tfoot id='aK5Ue'></tfoot><dl id='aK5Ue'><fieldset id='aK5Ue'></fieldset></dl></div>

        <bdo id='aK5Ue'></bdo><ul id='aK5Ue'></ul>

        <small id='aK5Ue'></small><noframes id='aK5Ue'>

        <tfoot id='aK5Ue'></tfoot>
      1. 如何使用 Struts 中的键值获取 json 对象?

        How to get json object using its key value in Struts?(如何使用 Struts 中的键值获取 json 对象?)
        <legend id='lOrGR'><style id='lOrGR'><dir id='lOrGR'><q id='lOrGR'></q></dir></style></legend>
        • <bdo id='lOrGR'></bdo><ul id='lOrGR'></ul>
            <tfoot id='lOrGR'></tfoot>
              <tbody id='lOrGR'></tbody>
                  <i id='lOrGR'><tr id='lOrGR'><dt id='lOrGR'><q id='lOrGR'><span id='lOrGR'><b id='lOrGR'><form id='lOrGR'><ins id='lOrGR'></ins><ul id='lOrGR'></ul><sub id='lOrGR'></sub></form><legend id='lOrGR'></legend><bdo id='lOrGR'><pre id='lOrGR'><center id='lOrGR'></center></pre></bdo></b><th id='lOrGR'></th></span></q></dt></tr></i><div id='lOrGR'><tfoot id='lOrGR'></tfoot><dl id='lOrGR'><fieldset id='lOrGR'></fieldset></dl></div>

                  <small id='lOrGR'></small><noframes id='lOrGR'>

                • 本文介绍了如何使用 Struts 中的键值获取 json 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 struts 开发 Web 服务.现在我想要 json 对象使用它的键值.然后我必须发布类似数组的东西作为回应.我不知道如何在 Struts 中做到这一点.我知道如何在 Servlets 中做到这一点.所以,我正在使用我尝试过的以下代码,但我认为它在 Struts 中有所不同.

                  I am working on web services in struts. Now I want json object using its key value. Then I have to post something like array in response. I have no idea how to do that in Struts. I know how to do it in Servlets. So, I am using the following code I have tried, but I think it is different in Struts.

                  JSONObject json = (JSONObject)new JSONParser().parse(jb.toString());
                                        String key_value= json.get("key").toString(); 
                  

                  那么,如何在 Struts 中做到这一点.还请告诉我如何解析 json 数组作为响应.

                  So, how to do it in Struts. Please also tell me how to parse json array in response.

                  推荐答案

                  使用 JSON 不需要将 JSON 发送到 Struts.即使可以将其配置为接受 JSON 内容类型,它也无济于事.您可以使用传入的数据对 Struts 进行普通请求.如果是 Ajax 调用,那么您可以使用类似

                  Working with JSON not necessary to send JSON to Struts. Even if it could be configured to accept JSON content type, it won't help you. You can use ordinary request to Struts with the data passed in it. If it's an Ajax call then you can use something like

                  $.ajax({
                     url: "<s:url namespace="/aaa" action="bbb"/>",     
                     data : {key: value},
                     dataType:"json",
                     success: function(json){
                       $.each(json, function( index, value ) {
                         alert( index + ": " + value );
                       });
                     }
                  }); 
                  


                  value 应该是通过 params 拦截器和 OGNL 填充的操作属性.success函数中返回的json应该是JSON对象,可以不解析直接使用.


                  The value should be an action property populated via params interceptor and OGNL. The json returned in success function should be JSON object and could be used directly without parsing.

                  您需要为属性key提供动作配置和setter.

                  You need to provide action configuration and setter for the property key.

                  struts.xml:

                  <package name="aaa" namespace="/aaa"  extends="json-default">
                    <action name="bbb" class="com.bbb.Bbb" method="ccc">
                     <result type="json">
                       <param name="root">
                     </result>
                    </action> 
                  </package>
                  


                  这个配置使用 "json-default" 包中的 "json" 结果类型,如果你使用 JSON 插件.


                  This configuration is using "json" result type from the package "json-default", and it's available if you use JSON Plugin.

                  动作类:

                  public class Bbb extends ActionSupport {
                  
                    private String key;
                    //setter
                  
                    private List<String> value = new ArrayList<>();
                    //getter
                  
                    public String ccc(){
                      value.add("Something");
                      return SUCCESS;
                    }
                  } 
                  


                  当您返回 SUCCESS 结果时,Struts 将通过调用其 getter 将 root 参数定义的 value 属性序列化为 JSON 结果序列化过程中的方法.


                  When you return SUCCESS result, Struts will serialize a value property as defined by the root parameter to the JSON result by invoking its getter method during serialization.

                  如果您需要将 JSON 发送到 Struts 操作,您应该阅读 this 答案.

                  If you need to send JSON to Struts action you should read this answer.

                  这篇关于如何使用 Struts 中的键值获取 json 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  <i id='quqb1'><tr id='quqb1'><dt id='quqb1'><q id='quqb1'><span id='quqb1'><b id='quqb1'><form id='quqb1'><ins id='quqb1'></ins><ul id='quqb1'></ul><sub id='quqb1'></sub></form><legend id='quqb1'></legend><bdo id='quqb1'><pre id='quqb1'><center id='quqb1'></center></pre></bdo></b><th id='quqb1'></th></span></q></dt></tr></i><div id='quqb1'><tfoot id='quqb1'></tfoot><dl id='quqb1'><fieldset id='quqb1'></fieldset></dl></div>
                    <tbody id='quqb1'></tbody>
                  1. <small id='quqb1'></small><noframes id='quqb1'>

                          <bdo id='quqb1'></bdo><ul id='quqb1'></ul>
                        • <legend id='quqb1'><style id='quqb1'><dir id='quqb1'><q id='quqb1'></q></dir></style></legend>
                          • <tfoot id='quqb1'></tfoot>