刚学java EE,然后配置struts2 package 和include模块配置。
#####################
#####
struts.xml
#####################
#####
WEB-INF/Content/{1}.jsp
这个WEB-INF前面是否指定根目录不重要,因为本身他就在根节点配置。
//struts.xml
class="cn.zhangzhipeng2023.struts2_test.action.LoginRegistProAction">
/WEB-INF/Content/index.jsp
/WEB-INF/Content/loginError.html
class="cn.zhangzhipeng2023.struts2_test.action.LoginRegistProAction"
method="registUser">
/WEB-INF/Content/index.jsp
/WEB-INF/Content/loginError.html
class="cn.zhangzhipeng2023.struts2_test.action.ViewUsersAction"
method="viewUsers">
/WEB-INF/Content/viewUsers.jsp
/WEB-INF/Content/loginError.html
WEB-INF/Content/{1}.jsp
WEB-INF/Content/{1}.html
#####################
#####
struts-admin.xml
#####################
#####
//struts-admin.xml
class="cn.zhangzhipeng2023.struts2_test.action.LoginRegistProAction">
/WEB-INF/Content/index.jsp
/WEB-INF/Content/loginError.html
WEB-INF/Content/{1}.jsp
WEB-INF/Content/{1}.html
#####################
#
#####################
#
#####################
#
访问:http://localhost:8081/struts2-test/admin/login
一直报404错误,因为我在web.xml 配置了error-code,所以一直是
page no found
于是将web.xml error-page节点注释掉,报了下面错误。看飘红字
HTTP Status 404 - /struts2-test/admin/WEB-INF/Content/login.jsp
type
message
description
Apache Tomcat/7.0.55
很明显,是配置出问题了,struts2配置中的namespace异常导致的,
struts.xml Action
但是struts-admin.xml 这么配置就是错误的,运行结果就是/struts2-test/admin/WEB-INF/Content/*** 当然找不到jsp文件了!!
所以在struts-admin.xmlAction中WEB-INF改成
/
WEB-INF
即可
#######################################################################
可以测试一下
http://localhost:8081/struts2-test/admin/login 正常访问了,
http://localhost:8081/struts2-test/admin/test 就报错了
HTTP Status 404 - /struts2-test/WEB-INF/Content/test.jsp
type
message
description
Apache Tomcat/7.0.55
很明显,这个404是因为文件不存在,而不是路径不错在了。