• <tfoot id='RSJd0'></tfoot><legend id='RSJd0'><style id='RSJd0'><dir id='RSJd0'><q id='RSJd0'></q></dir></style></legend>

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

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

        错误:找不到操作或结果没有为操作操作定义结果.部分和结果{“col1":“col1",“col2&q

        Error: Could not find action or result No result defined for action action.Part and result {quot;col1quot;:quot;col1quot;,quot;col2quot;:quot;col2quot;}(错误:找不到操作或结果没有为操作操作定义结果.部分和结果{“col1:“col1,“col2:“col2}) -

            <tbody id='27mUp'></tbody>
          • <legend id='27mUp'><style id='27mUp'><dir id='27mUp'><q id='27mUp'></q></dir></style></legend>
            • <small id='27mUp'></small><noframes id='27mUp'>

            • <tfoot id='27mUp'></tfoot>

                <i id='27mUp'><tr id='27mUp'><dt id='27mUp'><q id='27mUp'><span id='27mUp'><b id='27mUp'><form id='27mUp'><ins id='27mUp'></ins><ul id='27mUp'></ul><sub id='27mUp'></sub></form><legend id='27mUp'></legend><bdo id='27mUp'><pre id='27mUp'><center id='27mUp'></center></pre></bdo></b><th id='27mUp'></th></span></q></dt></tr></i><div id='27mUp'><tfoot id='27mUp'></tfoot><dl id='27mUp'><fieldset id='27mUp'></fieldset></dl></div>
                • <bdo id='27mUp'></bdo><ul id='27mUp'></ul>
                  本文介绍了错误:找不到操作或结果没有为操作操作定义结果.部分和结果{“col1":“col1",“col2":“col2"}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我没有收到来自服务器的 JSON 类型数据的响应.

                  I'm not getting response as JSON type data from server.

                  我正在使用 JSON 插件.

                  I'm using JSON plugin.

                  jQuery( "#dialog-form" ).dialog({ 
                      autoOpen: false,
                      height: 500,
                      width: 750,
                      modal: true,
                      buttons :{
                          "Search" : function(){
                              jQuery.ajax({type : 'POST',
                              dataType : 'json',
                               url : '<s:url action="part" method="finder" />',
                           success : handledata})
                          }
                      }
                  });
                  var handledata = function(data)
                  {
                      alert(data);
                  }
                  

                  如果 dataType = 'json' 我没有得到任何响应,但如果我没有提及任何 dataType,我将获得页面的 HTML 格式.

                  If dataType = 'json' I am not getting any response, but if I don't mention any dataType, I'm getting the HTML format of the page.

                  public String list(){
                      JSONObject jo = new JSONObject();
                      try {
                          Iterator it = findList.iterator();
                          while(it.hasNext()){
                               SearchResult part = (SearchResult) it.next();
                               jo.put("col1",part.getcol1());
                               jo.put("col2",part.getcol2());
                          }
                          log.debug("--------->:"+jo.toString());
                      } catch (Exception e) {
                          log.error(e);
                      }
                      return jo.toString();
                  }
                  

                  struts.xml:

                  <package name="default" namespace="/ajax" extends="json-default">
                    <action name="finder" 
                         class="action.Part" method="finder" name="finder">
                         <result type="json" />
                    </action>
                  </package>
                  

                  JSP 页面:

                  <div id="dialog-form" >
                      <form action="" id="channelfinder">
                          <textarea id="products" name="prodnbr"<s:property value='prodNbr'/>   
                      </form>
                  </div>
                  

                  控制台错误:

                  org.apache.struts2.dispatcher.Dispatcher - 找不到操作或结果没有为动作 action.Part 定义结果结果 {"col1":"col1","col2":"col2"}

                  org.apache.struts2.dispatcher.Dispatcher - Could not find action or result No result defined for action action.Part and result {"col1":"col1","col2":"col2"}

                  web.xml:

                      <?xml version="1.0" encoding="ISO-8859-1"?>
                       <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
                        <display-name>/parts</display-name>
                        <description>Parts List Web App</description>
                  
                      <filter>
                            <filter-name>struts-cleanup</filter-name>
                            <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
                          </filter>
                  
                          <filter>
                          <filter-name>sitemesh</filter-name>
                          <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
                          </filter>
                  
                         <filter>
                          <filter-name>struts2</filter-name>
                          <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
                          <init-param>
                              <param-name>actionPackages</param-name>
                              <param-value>com.action</param-value>
                          </init-param>
                      </filter>
                  
                  
                      <filter-mapping>
                          <filter-name>struts-cleanup</filter-name>
                          <url-pattern>/*</url-pattern>
                      </filter-mapping>
                  
                      <filter-mapping>
                          <filter-name>sitemesh</filter-name>
                          <url-pattern>/*</url-pattern>
                          <dispatcher>REQUEST</dispatcher>
                          <dispatcher>FORWARD</dispatcher>
                          <dispatcher>INCLUDE</dispatcher>
                      </filter-mapping>
                  
                      <filter-mapping>
                          <filter-name>struts2</filter-name>
                          <url-pattern>/*</url-pattern>
                      </filter-mapping>
                      <error-page>
                          <exception-type>java.lang.Throwable</exception-type>
                          <location>/errorPage.jsp</location>
                      </error-page>
                      <error-page>
                          <error-code>404</error-code>
                          <location>/errorPage.jsp</location>
                      </error-page>
                  
                    <!-- Spring -->
                    <context-param>
                      <param-name>contextConfigLocation</param-name>
                      <param-value>/WEB-INF/applicationContext.xml</param-value>
                    </context-param>
                    <listener>
                      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                    </listener>
                  
                    </web-app>
                  

                  我没有获取 jQuery 成功的数据.请纠正我,这里有什么问题?

                  I'm not getting data to jQuery success. Please correct me, whats wrong here?

                  推荐答案

                  一个 dataType : 'json' 被 jQuery Ajax 指定在执行操作和结果时 success 回调函数返回的数据类型,并从服务器.

                  A dataType : 'json' is used by jQuery Ajax to specify a data type that is expected to return by the success callback function when the action and result is executed, and a response returned from the server.

                  dataType(默认:智能猜测(xmljsonscripthtml))

                  dataType (default: Intelligent Guess (xml, json, script, or html))

                  类型:字符串

                  您期望从服务器返回的数据类型.如果没有指定,jQuery 将尝试根据响应的 MIME 类型推断它(XML MIME 类型将产生 XML,在 1.4 中 JSON 将产生一个 JavaScript 对象,在 1.4 中脚本将执行脚本,其他任何内容都将是以字符串形式返回).

                  The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string).

                  网址应正确指向操作映射.假设它将在默认命名空间中,否则您应该修改 URL 和映射以添加 namespace 属性.

                  The URL should correctly point to the action mapping. Assume it will be in the default namespace, otherwise you should modify URL and mapping to add the namespace attribute.

                  <script type="text/javascript">
                    $(function() {
                      $("#dialog-form").dialog ({
                        autoOpen: true,
                        height: 500,
                        width: 750,
                        modal: true,
                        buttons : {
                          "Search" : function() {
                            $.ajax({
                              url : '<s:url action="part" />',
                              success : function(data) {
                                //var obj = $.parseJSON(data);
                                var obj = data;
                                alert(JSON.stringify(obj));
                              }
                            });
                          }
                        }
                      });
                    });
                  </script>
                  

                  如果您手动构建 JSONObject,则不需要返回 json 结果类型.您可以将文本作为 流结果 返回,然后在需要时将字符串转换为 JSON.

                  Returning json result type is not needed if you build the JSONObject manually. You can return text as stream result then convert a string to JSON if needed.

                  struts.xml:

                  <package name="default" extends="struts-default">
                    <action name="part" class="action.PartAction" method="finder">    
                      <result type="stream">
                        <param name="contentType">text/html</param>
                        <param name="inputName">stream</param>
                      </result>
                    </action>
                  </package>
                  

                  行动:

                  public class PartAction extends ActionSupport {
                  
                    public class SearchResult {
                      private String col1;
                      private String col2;
                  
                      public String getCol1() {
                        return col1;
                      }
                  
                      public void setCol1(String col1) {
                        this.col1 = col1;
                      }
                  
                      public String getCol2() {
                        return col2;
                      }
                  
                      public void setCol2(String col2) {
                        this.col2 = col2;
                      }
                  
                      public SearchResult(String col1, String col2) {
                        this.col1 = col1;
                        this.col2 = col2;
                      }
                    }
                  
                    private InputStream stream;
                  
                    //getter here
                    public InputStream getStream() {
                      return stream;
                    }
                  
                    private List<SearchResult> findList = new ArrayList<>();
                  
                    public List<SearchResult> getFindList() {
                      return findList;
                    }
                  
                    public void setFindList(List<SearchResult> findList) {
                      this.findList = findList;
                    }
                  
                    private String list() {
                      JSONObject jo = new JSONObject();
                      try {
                        for (SearchResult part : findList) {
                          jo.put("col1", part.getCol1());
                          jo.put("col2", part.getCol2());
                        }
                        System.out.println("--------->:"+jo.toString());
                      } catch (Exception e) {
                        e.printStackTrace();
                        System.out.println(e.getMessage());
                      }
                      return jo.toString();
                    }
                  
                    @Action(value="part", results = {
                      @Result(name="stream", type="stream", params = {"contentType", "text/html", "inputName", "stream"}),
                      @Result(name="stream2", type="stream", params = {"contentType", "application/json", "inputName", "stream"}),
                      @Result(name="json", type="json", params={"root", "findList"})
                    })
                    public String finder() {
                      findList.add(new SearchResult("val1", "val2"));
                      stream = new ByteArrayInputStream(list().getBytes());
                      return "stream2";
                    }
                  }
                  

                  我已经使用结果类型和内容类型放置了不同的结果,以更好地描述这个想法.您可以返回这些结果中的任何一个,并返回字符串化或未字符串化的 JSON 对象.字符串化版本需要解析返回的数据以获取 JSON 对象.您还可以选择哪种结果类型可以更好地序列化以满足您的需求,但我的目标是表明,如果您需要序列化简单对象,则不需要 json 插件即可使其正常工作.

                  I have placed different results with result type and content type to better describe the idea. You could return any of these results and return JSON object either stringified or not. The stringified version requires to parse returned data to get the JSON object. You can also choose which result type better serializes to suit your needs but my goal was to show that if you need to serialize the simple object then json plugin is not necessary to get it working.

                  参考资料:

                  • 我们如何返回一个文本字符串作为响应
                  • 如何转换JSONObject 到字符串

                  这篇关于错误:找不到操作或结果没有为操作操作定义结果.部分和结果{“col1":“col1",“col2":“col2"}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)
                    <tfoot id='2eyI9'></tfoot>

                          <tbody id='2eyI9'></tbody>

                      • <small id='2eyI9'></small><noframes id='2eyI9'>

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