问题:maven搭建jsp/servlet web工程,在pom配置maven tomcat插件,tomcat能够正常启动。但是地址栏输入http://localhost:8999/访问时报错:
org.apache.jasper.JasperException: Unable to compile class for JSP:
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
因为tomcat中也有servlet-api,jsp-api等包,如果在pom文件也配置了servlet-api,jsp-api
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
</dependency>
那么就会产生jar包冲突。
解决办法:1、删除tomcat下的servlet-api,jsp-api等包
2、pom配置依赖的时候,使用<scope>provided</scope>,因为provided表明该包只在编译和测试的时候用,所以, 当启动tomcat的时候,就不会冲突了,完整依赖如下:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>