gpt4 book ai didi

spring - 无法解析类型 javax.servlet.http.HttpServletResponse。它是从所需的 .class 文件中间接引用的

转载 作者:行者123 更新时间:2023-12-05 09:23:59 24 4
gpt4 key购买 nike

我是 spring 的新手,尝试创建应用程序以便我可以了解它的工作原理。然而,当我编写代码时 Eclipse IDE 给出

类型 javax.servlet.http.HttpServletResponse 无法解析。它是从所需的 .class 文件中间接引用的

这是我的类(class)

package testPackage;  
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import domain.serviceLayer.UserService;
import domain.userDetails.User;

@SuppressWarnings("deprecation")
public class UserLoginFormController extends SimpleFormController {
private UserService userService;

public UserLoginFormController() {
setCommandClass(User.class);
setCommandName("user");
}
public void setUserService(UserService userService) {
this.userService = userService;
}

@Override
public ModelAndView onSubmit(Object command) throws Exception {
// TODO Auto-generated method stub

User user = (User) command;
userService.add(user);
ModelAndView modelAndView = new ModelAndView("success", "user", user);
return modelAndView;
}
}

和 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>learnSimpleFormController</groupId>
<artifactId>learnSimpleFormController</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<spring.version>3.2.3.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Servlet -->
<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>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<finalName>learnSimpleFormController</finalName>
</build>
</project>

请问是什么问题以及如何消除该错误

最佳答案

您的项目没有引用 servlet.jar,所以只需在您的 pom 中添加此依赖项即可

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
<version>1.2</version>
</dependency>

关于spring - 无法解析类型 javax.servlet.http.HttpServletResponse。它是从所需的 .class 文件中间接引用的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17647441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com