如何将欢迎页面设置为struts操作? [英] How can I set the welcome page to a struts action?

查看:122
本文介绍了如何将欢迎页面设置为struts操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于struts的webapp,我希望默认的欢迎页面是一个动作。我发现的唯一解决方案似乎是使欢迎页面成为包含重定向到操作的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");
%>

in index.jsp with

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆