Struts 1,重定向工作正常,但转发给出 404

发布于 2024-10-30 22:08:57 字数 388 浏览 7 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-11-06 22:08:57

return new ActionForward("items/search/", false); 失败的原因很简单。

通过将 redirect 设置为 false(您在 ActionForward 的第二个参数中执行此操作),您实际上是要求 Struts 检查您的逻辑名称(在您的情况下 items/search/) 与 ActionMapping 中的映射相对应。

我很确定在您的 struts-config.xml 中没有 (items/search/) 的 映射,并且因此,HTTP 404

阅读 ActionForward Documentation以了解其工作原理。

希望这有帮助!

The reason why return new ActionForward("items/search/", false); fails is simple.

By setting redirect to false (which you did in your 2nd parameter of ActionForward), you're effectively asking Struts to check your logical name (in your case items/search/) against the mapping in ActionMapping.

I'm quite sure that in your struts-config.xml there is no <forward> mapping for (items/search/) and thus, a HTTP 404.

Read ActionForward Documentation to understand how it works.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文