您的位置:首页 > 编程语言 > Java开发

【原创】java web strut…

2017-03-20 14:45 477 查看
刚学java EE,然后配置struts2 package 和include模块配置。
##########################struts.xml##########################
//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[/b] Status
report

message[/b] /struts2-test/admin/WEB-INF/Content/login.jsp

description[/b] The
requested resource is not available.


Apache Tomcat/7.0.55

很明显,是配置出问题了,struts2配置中的namespace异常导致的,
struts.xml Action
 WEB-INF/Content/{1}.jsp
这个WEB-INF前面是否指定根目录不重要,因为本身他就在根节点配置。

但是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[/b] Status
report

message[/b] /struts2-test/WEB-INF/Content/test.jsp

description[/b] The
requested resource is not available.


Apache Tomcat/7.0.55

很明显,这个404是因为文件不存在,而不是路径不错在了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: