1
我正在将应用程序从Struts 1迁移到Struts 2.我遇到了以下代码片段。请让我知道如何更换代码片段在Struts中2从Struts1迁移到Struts2
protected ActionForward getActionForward(FilterContext ctx, String key, boolean redirect) {
HashMap filterForwards = ctx.getFilterForwards();
String forwardPage = (String)filterForwards.get(key);
if(forwardPage == null)
return null;
return new ActionForward(forwardPage, redirect);
}
而另一代码片段是这样的: -
protected void setError(HttpServletRequest req, String msg) {
ActionMessages errors = new ActionMessages();
errors.add("exception", new ActionMessage(MSG_KEY, msg));
req.setAttribute(Globals.ERROR_KEY, errors);
}
我是否应该更换addActionError(msg)
上面的代码?
你可以发表你的完整的代码显示错误。通过这段代码,我们无法猜测你想要达到什么目的? – soorapadman
好吧,很难发布整个代码。但在第一种情况下,该功能用于页面重定向。在第二种情况下,代码用于设置全局动作错误。我希望它有帮助。 – Test