SpringMVC之使用Servlet原生API作为参数

SpringMVC的handler接收如下的ServletAPI类型的参数:

• HttpServletRequest
• HttpServletResponse
• HttpSession
• java.security.Principal
• Locale
• InputStream
• OutputStream
• Reader
• Writer
View Code

示例:

 

@RequestMapping("/testServletAPI")
    public void testServletAPI(HttpServletRequest request, HttpServletResponse response, Writer out) throws IOException {
        System.out.println("testServletAPI: " + request + "," + response);
        out.write("hello springmvc");
    }


对应的jsp:
<a href="test/testServletAPI">Test ServletAPI</a>
View Code

 

 运行项目,点击超链接:

控制台输出:

testServletAPI: org.apache.catalina.connector.RequestFacade@21f0bb9b,org.apache.catalina.connector.ResponseFacade@7d1613c6

 

posted on 2018-05-26 15:50  Javanumberone  阅读(291)  评论(0编辑  收藏  举报

导航