Struts 1,重定向工作正常,但转发给出 404
在 Struts 操作中,如果我返回一个重定向标志设置为 true 的 ActionForward,则一切都会按预期工作,即请求最终出现在所需的页面上。但是,当我将重定向设置为 false 时,会导致 404。需要注意的是,我不是直接重定向到 JSP(如 /WEB-INF/jsp/something.jsp 中),而是重定向到 URL(例如 items/search )。
它看起来像这样:
return new ActionForward("items/search/", true); // Works ok
return new ActionForward("items/search/", false); // Gives 404
有什么想法我可能做错了吗?
In a Struts action, if I return an ActionForward with a redirect flag set to true, everything works as expected, i.e. the request ends up on the desired page. But, when I set redirect to false, it results in 404. It's important to note, I'm not redirecting directly to JSP (as in /WEB-INF/jsp/something.jsp) but to an URL (e.g items/search).
It looks like this:
return new ActionForward("items/search/", true); // Works ok
return new ActionForward("items/search/", false); // Gives 404
Any ideas what I might be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
return new ActionForward("items/search/", false);
失败的原因很简单。通过将
redirect
设置为false
(您在ActionForward
的第二个参数中执行此操作),您实际上是要求 Struts 检查您的逻辑名称(在您的情况下items/search/
) 与ActionMapping
中的映射相对应。我很确定在您的
struts-config.xml
中没有 (items/search/
) 的
映射,并且因此,HTTP404
。阅读
ActionForward Documentation
以了解其工作原理。
希望这有帮助!
The reason why
return new ActionForward("items/search/", false);
fails is simple.By setting
redirect
tofalse
(which you did in your 2nd parameter ofActionForward
), you're effectively asking Struts to check your logical name (in your caseitems/search/
) against the mapping inActionMapping
.I'm quite sure that in your
struts-config.xml
there is no<forward>
mapping for (items/search/
) and thus, a HTTP404
.Read
ActionForward
Documentation to understand how it works.Hope this helps!