javaspringspring-mvchttpsession

Can't access HttpSession in Spring MVC @Controller class


I have a controller class in Spring MVC project. My code is like below:

@Controller
public class MainController {

@RequestMapping(value = "/doLogin")
public String login(@RequestParam("email") String email, @RequestParam("pwd") String password, Model model){
   //some code
  }
}

I want to pass HttpSession as method parameter but I'm not able to access HttpSession. I've attached a screenshot: enter image description here


Solution

  • This is because you don't have servlet api dependency in your classpath.

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>