SpringMVC(十三) RequestMapping 使用servlet原生API作为参数

SpringMVC支持以下Servlet方法:

HttpServletRequest

HttpServletResponse

HttpSession

Writer

Reader

Locale

InputStream

OutputStream

java.security.Principal

 

控制器参考代码:

复制代码
package com.tiekui.springmvc.handlers;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ServletApiTest {

    @RequestMapping("testServerletApi")
    public void testServerletApi(HttpServletRequest request,HttpServletResponse response,Writer writer) {
        System.out.println("request:" + request + ",response " + response);
        try {
            writer.write("Hello,This is a servlet writer response");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
复制代码

 

视图代码:

<a href="testServerletApi">Test Servlet Api Video 13</a>
posted @ 2018-12-18 11:30  尐鱼儿  阅读(1101)  评论(0编辑  收藏  举报