代码运行的好好的突然就报错了,错误提示如下:
Referenced file contains errors (http://struts.apache.org/dtds/struts-2.0.dtd). For more information, right click on the message in the Problems View and select
"Show Details..."
这样的错其实遇见过几次了,但每次再遇到的时候有不知所措了,所以记下来以便自己以后查找。
在Problems窗口中找到该消息,详情显示
The errors below were detected when validating the file "struts-2.0.dtd" via the file "struts.xml". In most cases these errors can be detected by validating "struts-2.0.dtd" directly. However it is possible that errors will only occur when struts-2.0.dtd is validated in the context of struts.xml.
原因找到了,找不到指定的dtd文件!jar包是肯定没错的,毕竟之前是能运行的,那么有错的就只能是 “http://struts.apache.org/dtds/struts-2.0.dtd” 这一句了。开始我怀疑是不是struts2不行了,后来到网上一查,结果是之前启动Myeclipse的时候没有网。
好吧,上解决办法。
1、现在有网了,为什么还显示有错误,Myeclipse缓存的问题。对struts.xml进行粘贴复制操作:ctrl +all--->ctrl+x---->ctrl+s--->ctrl+v
当然也有可能不成功,为什么,不知道。我的解决办法是重启Myeclipse然后再执行上面的操作,成功。
2、你有可能正处在一个没网的环境下,但是恰好你有那么一点点强迫症,下面这个方法就正适合你。
在顶上的myeclipse中单击preference--->myeclipse--->Files and Editors--->XML--->XML Catalog,选中右上方的User Specified Entries,单击add按钮,找到该dtd文件在本地的
路径:struts-2.1.8\src\core\src\main\resources\struts-2.0.dtd,Key Type 中选择uri,key中输入以下路径:http://struts.apache.org/dtds/struts-2.0.dtd,点击确定。回到struts.xml后
在任意位置输入空格保存就行了!