
1.哪些可以使用
MVC中的Handler方法可以接受ServletAPI类型的参数。
2.controller
package com.spring.it; 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 ServletApiControl {
@RequestMapping("/helloworld6")
public void hello(HttpServletRequest request,HttpServletResponse response,Writer out) throws Exception {
System.out.println("request="+request);
System.out.println("response="+response);
out.write("Spring mvc");
}
}
3.index
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<br>
<a href="helloworld6/">test servlet API</a>
</body>
</html>
4.效果
5.ps
Writer的由来
response.getWriter();