1、可以在web项目中设置默认的欢迎界面
在web.xml中设置代码如下:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
访问项目如:http://127.0.0.1:8080/myproject则直接调整到inex.jsp页面中
2、在struts.xml中设置默认页面,如果访问不存在的aciton在调整到默认页面
配置如下
<package name="default" extends="struts-default" namespace="/" >
<default-action-ref name="index"></default-action-ref>
<action name="index" >
<result >
/default.jsp
</result>
</action>
</package>
以上只是解决了访问不存在的action的时候的问题,如果访问不存在的jsp的时候则上面的没用。因为没走struts的aciton,则struts的所有拦截都没用。
3、在web.xml中设置404页面。
<error-page>
<error-code>404</error-code>
<location>/default.jsp</location>
</error-page>
这样子的话,访问任何不存在的页面,不如/agc/dgad/asfdasdfas.jsp这种不存在jsp的时候,则跳转到defaul.jsp中。
本文介绍了如何在web项目中设置默认欢迎页面和Struts2的默认Action,确保访问不存在的Action时重定向至指定页面。同时,通过在web.xml中配置404错误页面,当访问不存在的jsp时,系统将跳转到默认的错误处理页面。

1万+

被折叠的 条评论
为什么被折叠?



