java里写xml文件报错The content of element type "web-app" must match "(icon?,display- name?...

报这个错误是指格式不对

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*)".

在学习ssm整合maven时,原来的ssm框架里的web.xml内容直接复制到maven下的web.xml里就报上面的错,是因为xml文件不符合maven那个文件头的规范,

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

看来就是顺序不对,也有人说吧那个文件头删了或者改了就行 ,我觉得不太好,既然他那么规定的,就按照规定的顺序来就行了,报错信息就是规定的顺序。

display-name->description->distributable->context-param->filter->filter-mapping->listener->servlet->servlet-mapping

问题解决,附上示例

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  	
  	<context-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:applicationcontext.xml</param-value>
  	</context-param>
  	
  	<filter>
		<filter-name>characterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
</web-app>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值