使用Struts2

时间:2017-05-20 22:03:56

标签: json struts2

当我启动我的jsp时,我使用javascript函数在会话中向用户收费。 javascript函数使用带有struts2动作的JSON。这是代码:

JSP:

<body>
   <script>usarAJAXCargarCookie();</script>
   ...
</body>

使用Javascript:

function usarAJAXCargarCookie() {
   var userCookie = getCookie('userCookieSL');
   $.getJSON('ajaxCookie', {
      userCookie: userCookie
   }, function (jsonResponse) {
   });
}

struts.xml中

<action name="ajaxCookie" class="Acciones.HomeFavoritos" method="ajaxCookie">
   <result type="json">
      <param name="excludeNullProperties">true</param>
      <param name="noCache">true</param>
   </result>
</action>

HomeFavoritos.java

@SkipValidation
public String ajaxCookie() throws Exception{        
    if(sesion==null){
        sesion=ActionContext.getContext().getSession();
    }
    if(sesion.get("usuarioLogueado") == null || sesion.get("usuarioLogueado").equals("")){
        cargarUsuarioNoLogueado(sesion, userCookie);
    } else {
        cargarUsuarioLogueado(sesion);
    }
    return SUCCESS;
}

我收到此错误:

Grave:   Exception occurred during processing request: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:246)
    at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
    at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
    at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
    at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
    at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
    at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
    at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)

1 个答案:

答案 0 :(得分:0)

InvocationTargetException只是一个真正的例外,你没有向我们展示。

它可能是序列化异常,因此请考虑使用root object as described here,而不是序列化整个操作。

同时尝试在代码中使用英文名称,请不要使用不同于小写的内容编写包名称( A cciones.HomeFavoritos ...)