gpt4 book ai didi

java - 如何将欢迎页面设置为 struts 操作?

转载 作者:IT老高 更新时间:2023-10-28 20:48:01 24 4
gpt4 key购买 nike

我有一个基于 struts 的 webapp,我希望默认的“欢迎”页面成为一个操作。我发现的唯一解决方案似乎是使欢迎页面成为包含对操作的重定向的 JSP 的变体。例如,在 web.xml 中:

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

index.jsp中:

<% 
response.sendRedirect("/myproject/MyAction.action");
%>

肯定有更好的方法!

最佳答案

就个人而言,我会保持与您现在相同的设置,但将重定向更改为转发。这样可以避免将 header 发送回客户端并让他们发出另一个请求。

所以,特别是,我会替换

<% 
response.sendRedirect("/myproject/MyAction.action");
%>

在 index.jsp 中带有

<jsp:forward page="/MyAction.action" />

此更改的另一个影响是用户不会看到地址栏中的 URL 从“http://server/myproject”更改为“http://server/myproject/index.jsp”,因为转发发生在服务器内部。

关于java - 如何将欢迎页面设置为 struts 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39399/

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