在 JavaEE 工程中,会使用 XML 配置文件,XML 配置文件在解析时会加载 XSD 文件,但是 XSD 文件通常是在国外网站上的,经常会出现因为网络等原因造成的 XSD 文件加载不进来的问题,这时可以采用本地加载的形式。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>JavaWeb1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
第一步:下载 xsd 文件
打开http://xmlns.jcp.org/xml/ns/javaee网站,从中找到需要下载的 xsd 文件,我这里需要下载的是 web-app_4_0.xsd 文件。
将下载后的文件找一个位置放好,推荐将 xsd 文件专门放到一起。
第二步:配置 Eclipse
Window → Preferences → XML → XML Catalog → 选中 User Specified Entries → Add → 填好信息 → OK → Apply And Close
配置完成之后,使用方法还是和以前一样,不需要修改 web.xml 文件,但是加载的时候优先从本地加载。