一、问题描述

Web.xml中Element dispatcher is not allowed here_tomcat

二、解决方案

IDEA通过Maven构建的Web工程,默认web.xml的版本为2.3 ,由于版本太低,会导致web.xml在添加配置的时候出现问题
为了不出问题,我们可以直接将tomcat里面的web.xml头部拿过来
Web.xml中Element dispatcher is not allowed here_java_02
Web.xml中Element dispatcher is not allowed here_java_03

我们将文件的头部改为:

<?xml version="1.0" encoding="utf-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">

头部修改之后:
Web.xml中Element dispatcher is not allowed here_xml_04

可以看到,已经识别标签了