基于Eclipse通过maven-archetype-webapp原型创建一个Web项目后,其默认Servlet版本是2.3,Java版本是1.5。
解决方式(2种)
一、修改配置文件
1、点击Window->Show View->Navigator,修改项目的.setting目录下的org.eclipse.wst.common.project.facet.core.xml文件,将
<installed facet="jst.web" version="2.3"/>中 version="2.3" 修改成 version="3.0"
2、将web.xml中的配置换成3.0的配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>spring</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>
</web-app>
二、
1、将原有的web.xml中的必要内容备份后删除xml文件。
2、项目右键-->properties-->project facets,将Dynamic web module的对勾取消掉,点击apply,这时才能修改jdk版本,将jdk修改成自己的版本(版本大于1.6),然后将Dynamic web module的对勾打上并将版本修改成3.0,这时会出现一个Futher configuration available....,点进去设置Content directory(即web项目根目录),即maven的标准目录src/main/webapp,点击OK按钮,点击apply按钮,解决!