Error handling 迁移到Struts2的错误处理
要显示错误,我们需要包含错误消息的消息键。 我创建了一个名为Error handling 迁移到Struts2的错误处理,error-handling,struts2,resourcebundle,struts1,Error Handling,Struts2,Resourcebundle,Struts1,要显示错误,我们需要包含错误消息的消息键。 我创建了一个名为ApplicationError.properties的新资源包,其中包含以下属性: app.error=Error: {0} 我试图将这个类从struts1更改为struts2,但我在错误处理方面有问题。我在struts2中没有找到等效的类 public class MyAction extends Action{ public ActionForward execute(ActionMapping actionMa
ApplicationError.properties
的新资源包,其中包含以下属性:
app.error=Error: {0}
我试图将这个类从struts1更改为struts2,但我在错误处理方面有问题。我在struts2中没有找到等效的类
public class MyAction extends Action{
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
ActionErrors actionErrors = new ActionErrors();
ActionMessage message = new ActionMessage("app.error","Not Found Exception");
try{
//some code
}catch(NotFoundException e){
actionErrors.add(ActionErrors.GLOBAL_MESSAGE, message);
saveErrors(request, actionErrors);
return getErrorActionForward(actionMapping);
}
return getActionForward(actionMapping);
}
你能帮我做这个吗?你的动作类要扩展的签出类。然后使用它的方法添加错误
此类还实现了一个TextProvider
,因此您可以从资源中获取本地化消息
/**向此操作添加操作级错误消息*/
void addActionError(字符串A错误消息)
/**将操作级别消息添加到此操作*/
void addActionMessage(字符串aMessage)