原生API:
Servlet环境中一些有用的对象:
HttpServletRequest
HttpServletResponse
HttpSession
Reader
Writer
InputStream
OutputStream
java.security.Principal
1 配置环境
1.1 添加servlet运行环境:

1.2 引入pom坐标
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
2 使用原生API
直接在controller层的方法的参数列表中添加需要的对象即可
@RequestMapping("/index")
public String home(HttpSession session) {
System.out.println(session.getId());
return "home";
}
浙公网安备 33010602011771号