Tag: struts2 json plugin

Ajax错误struts2?

我有我的动作课: try{ tspNameIdMap = slsReqMgmtCommonRemote.getTspNameIdMap(Integer.parseInt(circleId)); throw new ReqMgmtException(“Message test”); } catch(ReqMgmtException rEx){ addActionError(“Action-Error: Request Management Exception thrown”); return ERROR; } 我正在进行AJAX调用并使用Struts2-Json-plugin以JSON格式获取tspNameIdMap 。 JS:AJAX的一部分: success: function(data){ alert(‘Updated DB’); }, error: function(data){ alert(data); } 我的struts.xml : tspNameIdMap 我想在我的Ajax错误函数中使用addActionError消息。 我还想在我的JSP中显示它。 我怎么能得到这个? Ps:我是否必须在属性文件中包含此ActionError消息? 我是第一次使用它。 帮帮我 编辑 :当我跟着@Prabhakar回答我得到了错误消息,但它在AJAX调用success时返回。 另一个问题是,当我把它放在我的JSP中时, actionerror没有显示出来。 JSP:

无法使用修饰符public访问org.springframework.aop.TruePointcut类的成员

我正在使用Struts和Struts JSON插件开发Spring应用程序。 当我运行应用程序时,它会出现以下错误(在Firebug中): org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers public 这是完整的堆栈跟踪: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public" org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:238) org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:171) org.apache.struts2.json.JSONWriter.process(JSONWriter.java:161) org.apache.struts2.json.JSONWriter.value(JSONWriter.java:127) org.apache.struts2.json.JSONWriter.write(JSONWriter.java:95) org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116) org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:196) org.apache.struts2.json.JSONResult.execute(JSONResult.java:170) com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) […]

在Struts 2中从Java获取JSON对象

我试图使用getJSON jQuery方法从java服务器获取响应文本。 虽然,当java类是简单格式( String , List和Map )时,我可以得到响应数据,但是在使用其他java对象时我无法获得成功数据。 以下Java类是简单类型并获取访问成功数据和工作 package com.awitd.framework.action; import com.opensymphony.xwork2.Action; public class getAllJson implements Action{ private String data; public String getData() { return data; } public void setData(String data) { this.data = data; } public String execute() { System.out.println(” this is from action”); data = “[“; data += “{“; data += “\”objid\”:\”” + […]

如何validation使用Struts2 Json插件发送的JSON而不抛出exception

假设一个动作中有一个Double变量,并且在请求体中发送的值是这样的 {“dblField”:””} 和interceptorStack看起来像: <!—-> true idIo 然后该动作抛出一个NumberFormatException ,根据这里的插件源代码很好 – https://github.com/apache/struts2/blob/STRUTS_2_3_15_X/plugins/json/src/main/java/org/apache/struts2/ JSON / JSONPopulator.java 但是这个exception没有在插件中处理,因此,从动作抛出exception返回,这导致global-exception-handler的触发。 如果使用查询字符串发送相同的请求, ?dblField=则操作返回INPUT 。 那么,我怎样才能使json-plugin以相同的方式返回INPUT并设置适当的fieldErrors而不是抛出NumberFormatException并触发globalExceptionHandler呢?