【记录】MyEclipse下web.xml报错Invalid content was found starting with element 'display-name'

来源:互联网 发布:软件测试入门书籍 编辑:程序博客网 时间:2024/06/06 03:29

新建一个Web Project之后,添加了一个servlet,MyEclipse自动生成web.xml:


<?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_3_1.xsd" id="WebApp_ID" version="3.1">  <display-name>MyServlet</display-name>  <servlet>    <servlet-name>TestServlet</servlet-name>    <display-name>TestServlet</display-name>    <description>Test of Servlet</description>    <servlet-class>com.anudesty.TestServlet</servlet-class>  </servlet>  <servlet-mapping>    <servlet-name>TestServlet</servlet-name>    <url-pattern>/servlet/TestServlet</url-pattern>  </servlet-mapping>  <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></web-app>

第7行<display-name>标签报错

cvc-complex-type.2.4.a: Invalid content was found starting with element 'display-name'. One of 
 '{"http://xmlns.jcp.org/xml/ns/javaee":servlet-class, "http://xmlns.jcp.org/xml/ns/javaee":jsp-file, "http://
 xmlns.jcp.org/xml/ns/javaee":init-param, "http://xmlns.jcp.org/xml/ns/javaee":load-on-startup, "http://
 xmlns.jcp.org/xml/ns/javaee":enabled, "http://xmlns.jcp.org/xml/ns/javaee":async-supported, "http://
 xmlns.jcp.org/xml/ns/javaee":run-as, "http://xmlns.jcp.org/xml/ns/javaee":security-role-ref, "http://
 xmlns.jcp.org/xml/ns/javaee":multipart-config}' is expected.

不管它也可以,项目正常运行

上网找办法:多是改动

<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_3_1.xsd" id="WebApp_ID" version="3.1">


里面的version以及web-app_3_1.xsd,但改动后由于找不到对应的文件而报错,大概不适用于较新的版本


最终是将

<display-name>TestServlet</display-name>
移动到

<servlet-name>TestServlet</servlet-name>
上面

然而

<description>Test of Servlet</description>
又报错

再移到<display-name>上面,问题解决,最终是这样的

<span style="font-family:SimSun;"><?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_3_1.xsd" id="WebApp_ID" version="3.1">  <display-name>MyServlet</display-name>  <servlet>    <description>Test of Servlet</description>    <display-name>TestServlet</display-name>    <servlet-name></span><span style="font-family: SimSun;">TestServlet</span><span style="font-family: SimSun;"></servlet-name></span><span style="font-family:SimSun;">    <servlet-class>com.anudesty.TestServlet</servlet-class>  </servlet></span>



0 0
原创粉丝点击