在Spring MVC 3中使用HttpServlet请求和响应对象

时间:2013-06-11 02:53:43

标签: spring-mvc spring-3

我在网上的Spring MVC示例中随处可见,我们可以使用HttpServlet请求&控制器中方法参数中的响应对象。但是当我使用它时。在下面的代码中给出。

  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;

  @Controller
  public class StudentController {

  public void testSyntax(HttpServletRequest request, HttpServletResponse response)
  {
System.out.println("Inside testSyntax");
  }

  }

编译器抛出错误。 HttpServletRequest请求无法解析为某个类型。 我正在使用Spring MVC 3.0。谁能告诉我它的原因。

1 个答案:

答案 0 :(得分:3)

您缺少几个import语句。

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

从这些类中获取这些类通常与您使用的每个应用程序容器不同。我最喜欢的例子是Tomcat:

<tomcat_base_dir>/lib/servlet-api.jar