-->

得到支柱JSON数据(get JSON data from struts)

2019-06-25 11:26发布

我可以得到的数据从操作功能,通过使用部分JSONArray.fromObject方法,使用AJAX接收JSON对象。 但非常奇怪的是相同的解决方案并没有豆文件。

该错误是下面。 我寻找一个解决的三大误区。 也许我需要导入java.lang.reflect.InvocationTargetException库,或添加在包中的一些库,或许Java,util.data与冲突util.sql.data 。 我不知道这是否会工作,即使我做了所有潜在的建议之上。

错误信息:

 [   00000015 SystemErr     R 

net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
    at net.sf.json.JSONObject.defaultBeanProcessing

(JSONObject.java:818)
    at net.sf.json.JSONObject._fromBean(JSONObject.java:699)
    at net.sf.json.JSONObject.fromObject(JSONObject.java:172)
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:274)
    at net.sf.json.JSONObject._processValue(JSONObject.java:2655)
    at net.sf.json.JSONObject.processValue(JSONObject.java:2721)
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2736)
    at net.sf.json.JSONObject.setValue(JSONObject.java:1424)
    at net.sf.json.JSONObject.defaultBeanProcessing

(JSONObject.java:765)
    at net.sf.json.JSONObject._fromBean(JSONObject.java:699)
    at net.sf.json.JSONObject.fromObject(JSONObject.java:172)
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:274)
    at net.sf.json.JSONArray._processValue(JSONArray.java:2513)
    at net.sf.json.JSONArray.processValue(JSONArray.java:2538)
    at net.sf.json.JSONArray.addValue(JSONArray.java:2525)
    at net.sf.json.JSONArray._fromCollection(JSONArray.java:1056)
    at net.sf.json.JSONArray.fromObject(JSONArray.java:123)
    at net.sf.json.JSONArray.fromObject(JSONArray.java:105)
    at 

(SearchAction.java:675)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke

(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke

(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.apache.struts.actions.DispatchAction.dispatchMethod
Caused by: java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke

(NativeMethodAccessorImpl.java:60)

Caused by: java.lang.IllegalArgumentException
    at java.sql.Date.getHours(Date.java:79)
    ... 69 more`]

Answer 1:

试试这个,会帮助你在Struts中2.0.14与jsonplugin-0.32.jar。

struts.xml中:

<struts>
     <package name="example" extends="json-default">
        <action name="HelloWorld" class="example.HelloWorld"  >
            <result type="json" />
        </action>
              <action name="HelloWorld1" class="example.HelloWorld"  >
            <result name="success" >example/HelloWorld.jsp</result>
        </action>
    </package>
</struts>

动作类Helloworld.java:

package prabhakar;

import glb.DB;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Prabhakar
 */
public class HelloWorld  {


    private List<StateMaster> stateList= new ArrayList<StateMaster>();
    private List<RegnMaster> regnList= new ArrayList<StateMaster>();

    private Integer stateId;
    public Integer getStateId()
    {
    return this.stateId;
    }
    public void setStateId(Integer stateId)
    {
    this.stateId=stateId;
    }
    public List<StateMaster> getStateList() {
        return stateList;
    }

    public void setStateList(List<StateMaster> stateList) {
        this.stateList = stateList;
    }
     public void setRegnList(List<RegnMaster> regnList) {
        this.regnList = regnList;
    }
    public List<RegnMaster> getRegnList() {
        return regnList;
    }

    public String execute() throws Exception {

        stateList=DB.getStateData()//
        if(stateId !=null)
          {
         regnList=DB.getRegnByStateId(stateId);
          }

        //setMessage(getText(MESSAGE));
        return "success";
    }

    /**
     * Provide default valuie for Message property.
     */

}

您可以直接拨打HelloWorld.action查看JSON数据,否则你可以将JSON数据绑定到下面的表单元素。

JSP页面的helloWorld.jsp:

  /*
     Prabhakar
  */

<%@ page contentType="text/html; charset=UTF-8" %>

<%@ taglib prefix="s" uri="/struts-tags" %>
<script>
<%@include file="../js/jquery-1.7.1.min.js"%>
</script>
    <html>

<!-- JavaScript Plugins -->
  <script>
       function getLoad(){


       var stateId = $('#state').val();

$.getJSON('HelloWorld.action', {'stateId': stateId},
    function(data) {

           var divisionList = (data.regnList);

                var options = $("#regn");
                options.find('option')
    .remove()
    .end();
     options.append($("<option />").val("-1").text("--Select--"));
$.each(divisionList, function() {

    options.append($("<option />").val(this.regnId).text(this.regnName));
});
    }
);}
   </script>

<!-- jQuery-UI Dependent Scripts -->

    <body>
        State List <s:select name="stateId" list="stateList" id="state" listKey="stateId" onchange="getLoad()" listValue="stateName" headerKey="0" headerValue="--select--" />
        Regn List <s:select name="regnId"  list="regnList" listKey="regnId" id="regn" listValue="regnName" headerKey="0" headerValue="--select--" />
    </body>
</html>

编码愉快:)



文章来源: get JSON data from struts
标签: ajax json struts