如何将servlet api添加到我的pom.xml中

fly*_*ire 37 java maven-2 servlets pom.xml

如何将servlet API添加到项目的pom.xml中

mvnrepository.com有很多servlet api和类似命名的项目,我不知道哪个是正确的.或者他们都好吗?

dig*_*oel 46

我相信大多数web/app服务器捆绑了一个版本的servlet api,因此你不希望在你的.war文件中捆绑api.您需要找出服务器附带的版本,然后才能使用

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>${servlet-api-version}</version>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

用您的版本替换servlet-api-version.您需要指定"提供的"范围,以便api.jar不包含在war文件中.