Spring MVC 使用Servlet原生API作为参数
具体看代码:
1 @RequestMapping("/testServletAPI")
2 public void testServletAPI(HttpServletRequest request,
3 HttpServletResponse response,HttpSession session,
4 Write r out) throws IOException{
5 System.out.println(request);
6 System.out.println(response);
7 System.out.println(session);
8 out.write("hello");
9 }
代码解析:
很明显,要使用Sevlet的一些API,只要直接将其作为参数传入即可。你需要request,就传入request, 需要session,就传入session。springmvc支持传入的Sevlet原生api一共有以下这些:
1. HttpServletRequest
2. HttpServletResponse
3. HttpSession
4. java.security.Principal
5. Locale
6. InputStream
7. OutputStream
8. Reader
9. Writer