正常情况下 http://127.0.0.1:8080/struts2-showcase/index.action
我想访问 http://127.0.0.1:8080/struts2-showcase/
直接返回和上面一样的效果,不需要跳转.
请问怎么配置呢?
struts2中是允许配置默认后缀的,共有两种使用方式:
1.有后缀的配置如下,配置文件如下:
<struts>
<constant name="struts.action.extension" value="html"/>
<package name="default" namespace="/" extends="struts-default">
<action name="SayStruts2">
<result> pages/printStruts2.jsp</result>
</action>
</package>
</struts>
访问"SayStruts2"action类可以通过:http://localhost:8080/Struts2Example/SayStruts2.html
2.无后缀的配置文件:
<struts>
<constant name="struts.action.extension" value=""/>
<package name="default" namespace="/" extends="struts-default">
<action name="SayStruts2">
<result> pages/printStruts2.jsp</result>
</action>
</package>
</struts>
访问"SayStruts2"action类可以通过: http://localhost:8080/Struts2Example/SayStruts2
========================================================
补充:struts2配置默认首页:
方法一:
<default-action-ref name="SayStruts2"></default-action-ref>
<action name="SayStruts2">
<result> struts2-showcase/index.action</result>
</action>
方法二:定义过滤器继承struts的过滤器,把上下文根路径排除,不让根路径请求转发到struts的过滤器中去,同时在web.xml定义默认的欢迎页。