java操作错误不会显示在JSP上
我曾尝试在action类中添加操作错误,并在JSP页面上打印它们
当异常发生时,它将进入catch块,并在控制台中打印“插入异常时出错,请与管理员联系”
在catch块中,我添加了addActionError()
,并尝试在jsp页面中打印它。。。
但该消息未显示在jsp页面中
我可能错过了什么或做错了什么
Struts映射:
<action name="dataUpdate" class="foo.bar.myAction" method="updation">
<result name="success" type="redirectAction">
../Aggregator/redirectToDataUpdate
</result>
</action>
动作类:
public String updation() throws JiffieTransactionException{
try {
// do stuff...
} catch (NumberFormatException e) {
addActionError("Error in inserting the Exception, Contact the Admin");
System.out.println("Error in inserting the Exception, Contact the Admin");
e.printStackTrace();
}
return SUCCESS;
}
打印操作错误的JSP代码:
<s:if test="hasActionErrors()">
<br></br>
<div class="errors">
<font color="red">
<s:actionerror/>
</font>
</div>
</s:if>
# 1 楼答案
在catch块中添加一条操作消息,如:
然后在jsp上写:
# 2 楼答案
执行重定向操作时,会创建一个新请求,因此所有actionMessages、actionErrors以及所有其他参数(未明确声明在struts配置中传递)都会丢失
然后
如果出现错误,则返回类型为dispatcher的不同结果,例如
ERROR
: