阿贾克斯错误Struts2的? [英] Ajax error struts2?
问题描述
我在我的动作类:
尝试{
tspNameIdMap = slsReqMgmtCommonRemote.getTspNameIdMap(的Integer.parseInt(circleId));
抛出新ReqMgmtException(信息测试);
}
赶上(ReqMgmtException REX){
addActionError(操作错误:请求管理引发的异常);
返回错误;
}
我在做一个AJAX调用和使用的 Struts2的JSON的-插件获得 tspNameIdMap
以JSON格式。
记者:AJAX的部分:
成功:功能(数据){
警报('更新数据库');
},
错误:功能(数据){
警报(数据);
}
我的struts.xml
:
<作用NAME =findTspNameIdMap
类=cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction方法=findTspNameIdMap>
<结果名称=成功TYPE =json的>
< PARAM NAME =根>
tspNameIdMap<! - tspNameIdMap将在JSON形式返回 - >
< /参数>
< /结果>
< /作用>
我希望我的 addActionError
的消息在我的Ajax误差函数。我也希望在我的JSP中显示出来呢。我怎样才能得到呢?
诗:我必须包括在属性这个ActionError消息文件?我使用它的第一次。帮助
修改:我跟着@Prabhakar回答,我得到了错误的信息,但它得到的AJAX调用的成功
返回。
另一个问题是,当我把这个在我的JSP中, actionerror
是没有得到显示。
JSP:
< S:如果测试=hasActionErrors()>
&所述氏:actionerror />
< / S:如果>
您可以配置结果错误
返回渲染错误页面片段Ajax响应。
&LT;结果名称=错误&GT; /error.jspx< /结果&GT;
error.jspx:
&LT;%@ taglib伪preFIX =SURI =/ Struts的标签%&GT;
&LT;%
了request.setAttribute(装饰,无);
response.setHeader(缓存控制,无缓存); // HTTP 1.1
response.setHeader(杂,无缓存); // HTTP 1.0
response.setDateHeader(过期,0); // prevents在代理服务器高速缓存
%&GT;
&LT; S:如果测试=hasActionErrors()&GT;
&所述氏:actionerror /&GT;
&LT; / S:如果&GT;
I have in my action class:
try{
tspNameIdMap = slsReqMgmtCommonRemote.getTspNameIdMap(Integer.parseInt(circleId));
throw new ReqMgmtException("Message test");
}
catch(ReqMgmtException rEx){
addActionError("Action-Error: Request Management Exception thrown");
return ERROR;
}
I am doing an AJAX call and using Struts2-Json-plugin to get tspNameIdMap
in JSON form.
JS: Part of AJAX:
success: function(data){
alert('Updated DB');
},
error: function(data){
alert(data);
}
My struts.xml
:
<action name="findTspNameIdMap"
class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction" method="findTspNameIdMap">
<result name="success" type="json">
<param name="root">
tspNameIdMap <!-- tspNameIdMap will be returned in JSON form -->
</param>
</result>
</action>
I want my addActionError
message in my Ajax error function. I will also want to display it in my JSP then. How can I get this?
Ps: Do I have to include this ActionError message in a properties file? I am using it for first time. Help
EDIT : As i followed @Prabhakar answer I got the error message, but it got returned in the success
of the AJAX call.
Another issue is that, when i put this in my JSP, the actionerror
is not getting displayed.
Jsp:
<s:if test="hasActionErrors()">
<s:actionerror />
</s:if>
You can configure result ERROR
to return the rendered error page fragment to the Ajax response.
<result name="error">/error.jspx</result>
error.jspx:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
request.setAttribute("decorator", "none");
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<s:if test="hasActionErrors()">
<s:actionerror />
</s:if>
这篇关于阿贾克斯错误Struts2的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!