我想在用户访问我的网站时默认运行一个操作。
这是一个使用Java EE
和Struts2
开发的经典Tomcat
项目。我知道如何在web.xml中执行此操作:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
但是,我想通过Struts2的行动来做到这一点。
答案 0 :(得分:1)
尝试此代码,看看是否有效。
<action name="index" class="myaction">
<result>/index.jsp</result>
</action>
你也可以试试这个。
<welcome-file-list>
<welcome-file>/myfolder/index.action</welcome-file>
</welcome-file-list>
另一种方式是你的索引jsp是你做这样的事情
<% response.sendRedirect("home.do"); %>
但我不相信这是一种合适的方法
答案 1 :(得分:1)
另一种选择是使用default-action-ref
标记来指示在发出不映射到任何操作的请求时要调用的默认操作。
<default-action-ref name="home"/>
<action name="home" class="myaction">
<result>/WEB-INF/jsp/home.jsp</result>
</action>