如何将欢迎页面设置为 struts 操作? [英] How can I set the welcome page to a struts action?
问题描述
我有一个基于 struts 的 web 应用程序,我希望默认的欢迎"页面成为一个操作.我发现的唯一解决方案似乎是使欢迎页面成为包含指向操作的重定向的 JSP 的变体.例如,在 web.xml
中:
I have a struts-based webapp, and I would like the default "welcome" page to be an action. The only solutions I have found to this seem to be variations on making the welcome page a JSP that contains a redirect to the action. For example, in web.xml
:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
在index.jsp
中:
<%
response.sendRedirect("/myproject/MyAction.action");
%>
当然有更好的方法!
推荐答案
就我个人而言,我会保留您现在的相同设置,但将重定向更改为转发.这避免了将标头发送回客户端并让他们发出另一个请求.
Personally, I'd keep the same setup you have now, but change the redirect for a forward. That avoids sending a header back to the client and having them make another request.
所以,特别是,我会替换
So, in particular, I'd replace the
<%
response.sendRedirect("/myproject/MyAction.action");
%>
在 index.jsp 中
in index.jsp with
<jsp:forward page="/MyAction.action" />
此更改的另一个影响是用户不会看到地址栏中的 URL 更改为 "http://server/myproject" 到 "http://server/myproject/index.jsp",如转发发生在服务器内部.
The other effect of this change is that the user won't see the URL in the address bar change from "http://server/myproject" to "http://server/myproject/index.jsp", as the forward happens internally on the server.
这篇关于如何将欢迎页面设置为 struts 操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!