• <bdo id='2x5du'></bdo><ul id='2x5du'></ul>

    <small id='2x5du'></small><noframes id='2x5du'>

  1. <legend id='2x5du'><style id='2x5du'><dir id='2x5du'><q id='2x5du'></q></dir></style></legend>
  2. <i id='2x5du'><tr id='2x5du'><dt id='2x5du'><q id='2x5du'><span id='2x5du'><b id='2x5du'><form id='2x5du'><ins id='2x5du'></ins><ul id='2x5du'></ul><sub id='2x5du'></sub></form><legend id='2x5du'></legend><bdo id='2x5du'><pre id='2x5du'><center id='2x5du'></center></pre></bdo></b><th id='2x5du'></th></span></q></dt></tr></i><div id='2x5du'><tfoot id='2x5du'></tfoot><dl id='2x5du'><fieldset id='2x5du'></fieldset></dl></div>
    <tfoot id='2x5du'></tfoot>
    1. 如何在 Struts 2 中创建一个动作来接受来自用户界面的动态 JSON 数据?

      时间:2023-09-25

              <tbody id='kAQCs'></tbody>

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

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

                本文介绍了如何在 Struts 2 中创建一个动作来接受来自用户界面的动态 JSON 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想要一个 Action 类,它应该接受从用户界面构造的 JSON 字符串,而 Action 类中没有 setter 和 getter.

                I would like to have an Action class which should accept a JSON string constructed from user interface with no setter and getter in the Action class.

                有可能吗?如果是这样,我需要在 Action 类和配置文件 (struts.xml) 中遵循哪些约定?

                Is it possible? If so, what conventions would I need to follow in Action class and in configuration files (struts.xml)?

                推荐答案

                将它们作为内容发布,类型为 application/json".您可以通过一个简单的 jQuery Ajax 调用来完成,您可以在其中指定 content-typedataType.

                Post them as content with type "application/json". You may do it with a simple jQuery Ajax call where you could specify the content-type and dataType.

                $.ajax({
                   type: "POST",
                   url: "/the/action/url",     
                   data : {},
                   dataType:"JSON",
                   contentType: "application/json; charset=utf-8"
                });
                

                使用 json-lib-2.3 将 json 插件 添加到项目依赖项中-jdk15.jar.拦截器 json 从请求中读取并填充操作.

                Add json plugin to the project dependencies with json-lib-2.3-jdk15.jar. The plugin supplied with the interceptor json that reads and populates an action from the request.

                如果您不想填充操作,则不应使用此拦截器.而是使用此库或任何其他第三方库手动解析请求以获取 JSONObject 类.或者您可以重写拦截器并注释使用 JSONPopulator 类 但使用 JSONUtil 类.

                If you don't want to populate the action then you should not use this interceptor. Instead manually parse the request with this or any other third party library to get the JSONObject class. Or you could rewrite the interceptor and comment that code that is using JSONPopulator class but deserialize the object with JSONUtil class.

                此外,您可能会发现 this 示例在手动创建/解析 JSON 数据时很有用.

                Also, you might find this examples useful when manually creating/parsing JSON data.

                这篇关于如何在 Struts 2 中创建一个动作来接受来自用户界面的动态 JSON 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:异常启动过滤器 struts2 - 尝试添加 JAR,但结果相同 下一篇:“找不到 Struts 调度程序"在 WebLogic 12.1.3 上部署应用程序时出错

                相关文章

              • <legend id='LkKyJ'><style id='LkKyJ'><dir id='LkKyJ'><q id='LkKyJ'></q></dir></style></legend>

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

                2. <tfoot id='LkKyJ'></tfoot>
                    <bdo id='LkKyJ'></bdo><ul id='LkKyJ'></ul>

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