web.xml中 web-app报错标红
刚开始学习javaweb,遇到错误如下:
1.报错图片:
2.报错更改
The content of element type “web-app” must match “(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)”.
好像是在说,web-app里的东西要按照这样这样的顺序,我搜了一下后,尝试把自己代码中的两个注册servlet操作放到一起,声明servlet请求路径的放到下面,解决了报错问题。
更改如下:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- //注册Servlet-->
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.jp.servlet.HelloServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>error</servlet-name>
<servlet-class>com.jp.servlet.ErrorServlet</servlet-class>
</servlet>
<!-- //Servlet的请求路径-->
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>error</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>