0

I have seen everywhere in the Spring MVC examples on net that we can use HttpServlet request & response objects in the method parameter in the controller. But when I am using it. Given in the below code.

  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");
  }

  }

The compiler is throwing an error. HttpServletRequest request cannot be resolved to a type. I am using Spring MVC 3.0. Can anyone tell me the reason for it.

1
  • In console the exception is java.lang.ClassNotFoundException: HttpServletRequest Commented Jun 11, 2013 at 2:56

1 Answer 1

3

You are missing a couple of import statements.

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

Where you get these classes from typically is different per application container you use. My favorite example is Tomcat:

<tomcat_base_dir>/lib/servlet-api.jar
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help, do I have to explicitly add servlet.api jar? Is it not within the Spring MVC jars??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.