2017-05-20 63 views
-1

當我啓動我的jsp時,我使用javascript函數在會話中爲用戶收費。 javascript函數使用JSON和struts2操作。這是代碼:使用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) 
+0

這是目前還不清楚什麼是你想返回的JSON響應。 –

回答

0

InvocationTargetException只是周圍的真實異常的包裹,你沒有向我們展示。

這可能是一個序列化異常,所以考慮使用root object as described here,而不是序列化整個操作。

也可以嘗試在代碼中使用英文名字,並請,從來沒有與小寫不同的東西寫包名(一個 cciones.HomeFavoritos ...)