eclipse中新建maven web工程,会因为缺少servlet,jsp,jstl的依赖而报错,但如果直接依赖到pom.xml中后,会与tomcat中的相关jar包冲突,此时:
<dependency> <groupId> jstl</groupId > <artifactId> jstl</artifactId > <version>${version}</ version> </dependency> <!-- Servlet -api --> <dependency> <groupId> javax.servlet</groupId > <artifactId> servlet-api</artifactId> <version>${version}</ version> <scope> provided</ scope> </dependency> <dependency> <groupId> javax.servlet</groupId > <artifactId> jsp-api</artifactId> <scope> provided</ scope> <version>${version}</ version> </dependency>
但还有些时候,我们会引进一些高级依赖,这些依赖底层会自动依赖servlet,jsp的依赖,这样的war包如果直接到tomcat中也会引发冲突,所以此时应该将它们排除,如果这会引发编译的问题,那么依旧可以在pom.xml中引入上面的依赖,但注意版本与高级以来中这些jar包版本一致即可:
<dependency> <groupId>org.glassfish.web</groupId> <artifactId>jstl-impl</artifactId> <version>${version}</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> </exclusion> <exclusion> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl-api</artifactId> </exclusion> </exclusions> </dependency>
如果你手头没有配置好的版本,那么,可以用我这个:
<dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency>