Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 867
Joshgun Avatar asked Mar 07 '23 20:03

Joshgun


2 Answers

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>
like image 165
Mykola Yashchenko Avatar answered Mar 10 '23 10:03

Mykola Yashchenko


You need to have java servlet in your project. Add this to your pom.xml

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>
like image 28
Atimene Nazim Avatar answered Mar 10 '23 10:03

Atimene Nazim