SpringMVC中支持原生态的HttpServletRequest和HttpServletResponse等等。
SpringMVCTest.java
package com.hust.springmvc1;
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;
import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@RequestMapping("/springmvc")
public class SpringMVCTest {
private static final String SUCCESS = "success";
/**
* 可以使用 Servlet 原生的API作为目标方法的参数
* 具体支持以下类型
* HttpServletRequest
* HttpServletResponse
* HttpSession
* java.security.Principal
* OutputStream
* Reader
* Writer
* @throws IOException
*/
@RequestMapping("/testServletAPI")
public void testServletAPI(HttpServletRequest request,
HttpServletResponse response, Writer out) throws IOException {
System.out.println("testServletAPI, " + request + "," + response);
// 为了测试能用原生的Servlet中的Writer,先把返回值String去掉改成void,一样能在屏幕写出String
out.write("hello springMVC");
// return SUCCESS;
}
}
比较简单,基本一看都能明白。