码迷,mamicode.com
首页 > Windows程序 > 详细

使用servlet原生API作为参数

时间:2016-11-12 11:48:21      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:success   log   row   handle   vax   apache   turn   uri   void   

SpringMVC的Handler方法可以使用servlet原生的API作为目标方法的参数,具体支持以下类型:

* HttpServletRequest

* HttpServletResponse

* HttpSession

* java.security.Principal

* Locale InputStream

* OutputStream

* Reader

* Writer

此时,需要在pom.xml增加如下配置(别忘了版本<servlet-api.version>3.1.0</servlet-api.version>):

1 <!-- servlet -->
2         <dependency>
3             <groupId>javax.servlet</groupId>
4             <artifactId>javax.servlet-api</artifactId>
5             <version>${servlet-api.version}</version>
6             <scope>provided</scope>
7         </dependency>
 1 @RequestMapping("/springmvc")
 2 @Controller
 3 public class SpringMVCTest {
 4     private static final String SUCCESS = "success";
 5     @RequestMapping("/testServletAPI")
 6     public void testServletAPI(HttpServletRequest request,HttpServletResponse response,Writer out) throws IOException {
 7         System.out.println("testServletAPI," + request + "," + response);
 8         out.write("hello");
 9         //return SUCCESS;
10     }

运行结果:

           在页面中会打印出hello  在console中:

           testServletAPI,org.apache.catalina.connector.RequestFacade@6dfcd74,org.apache.catalina.connector.ResponseFacade@fd25fbe

使用servlet原生API作为参数

标签:success   log   row   handle   vax   apache   turn   uri   void   

原文地址:http://www.cnblogs.com/wangna----558169/p/6035047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!