gpt4 book ai didi

java - 将 index.jsp 重定向到 Struts 2 Action

转载 作者:行者123 更新时间:2023-11-30 07:08:38 25 4
gpt4 key购买 nike

相关: 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" />

我只使用注释,没有 XML 文件配置。

@Action (value = "indexRedir", results = 
{ @Result (location = "index-login.jsp", name = "ok") } )

编辑

澄清一下,这是通过 response.sendRedirect 发送到浏览器的 http header :

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 页面的内容。 Google 网站管理员工具和一些漫游器不会关注这样的页面。

在这里查看更多信息:http://en.wikipedia.org/wiki/HTTP_302

最佳答案

为了转发到一个 Action ,你必须配置过滤器在转发上运行;通常他们不会,尽管这是依赖于容器的。例如Tomcat下:

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher> <!-- If you want includes as well -->
</filter-mapping>

就我个人而言,我不觉得重定向特别不优雅,而且非常标准。

另一个好处是您可以将人们带入基于操作的应用程序;随着转发您的 URL 不会改变。通常,您希望禁止基于 JSP 的 URL。

关于java - 将 index.jsp 重定向到 Struts 2 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23890430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com