SpringMVC支持的原生API有:HttpServletRequest,HttpServletResponse下面来看获取原生API的“正确姿势”
1.首先定义一个控制器,带请求
@Controller
@RequestMapping("/param")
public class ParamController {
/**
* 获取Servlet原生的API
* @return
*/
@RequestMapping("/testServlet")
public String testServlet(HttpServletRequest request, HttpServletResponse response){
System.out.println("执行了...");
HttpSession session = request.getSession();
System.out.println(session);
ServletContext servletContext = session.getServletContext();
System.out.println(servletContext);
System.out.println(response);
return "success";
}
}
2.然后写页面
<a href="param/testServlet">获取Servlet原生的API</a>