【发布时间】:2014-07-16 10:13:21
【问题描述】:
相关: How can I set the welcome page to a struts action?
我正在尝试将我的欢迎页面 index.jsp 重定向到一个操作 (Struts2)。 相关帖子中的任何选项都不适合我:
type Status report
message /malelo/indexRedir
description The requested resource (/malelo/indexRedir) is not available.
我遵循这个 FLOW 结构:
http://localhost:8580/malelo/ SEND TO WELCOME PAGE
---> (root)index.jsp SEND USER TO (by redirect, I need forward)
---> (indexRedir) IndexAction.java SEND USER TO
---> (WEB-INF/content) index-login.jsp
这行得通,但不太优雅(index.jsp):
<%
response.sendRedirect("indexRedir");
%>
我正在尝试这样做(index.jsp):
<jsp:forward page="indexRedir" />
我只使用 Annotation,请不要配置 XML 文件。
@Action (value = "indexRedir", results =
{ @Result (location = "index-login.jsp", name = "ok") } )
编辑
澄清一下,这是通过 response.sendRedirect 发送到浏览器的 http 标头:
HTTP/1.1 302 Found
Date: Tue, 27 May 2014 16:15:12 GMT
Location: http://cmabreu.com.br/basico/
Content-Length: 0
Connection: close
Content-Type: text/plain
此位置 (http://cmabreu.com.br/basico/) 指向 index.jsp,其中:
<%
response.sendRedirect("indexRedir");
%>
并显示 indexRedir 动作指向的 JSP 页面的内容。谷歌网站管理员工具和一些机器人不关注这样的页面。
在此处查看更多信息:http://en.wikipedia.org/wiki/HTTP_302
【问题讨论】:
-
any 操作是否有效?另请注意,转发与重定向不同;如果你想 forward (我不会,因为你的 URL 不会改变),那么你需要配置你的服务器以通过拦截器处理转发,例如,对于 Tomcat,@987654324 @.
-
是的。我的系统运行良好,有 50 个动作。我知道转发不是相同的重定向。我想改变只是因为我知道这一点。我的照片让人们感到困惑,对不起。不是文件夹,是流程。
-
请不要在不告诉我为什么和不理解问题的情况下投反对票!请不要删除答案!
-
欢迎来到 S2 标签用户之一的世界;我为他的行为道歉。您可以在转发之外访问
indexRedir操作吗? -
是的!在欢迎页面
index.jsp中使用response.sendRedirect("indexRedir")可以正常工作。顺便说一句,您在其他帖子中的解决方案(您在上面给我的链接)有效。请把它放在一个答案中。现在我可以从 index.jsp 中<jsp:forward page="indexRedir" />!
标签: java struts2 annotations struts2-convention-plugin