009 使用servlet API作为参数

时间:2023-03-09 17:46:09
009 使用servlet API作为参数

1.哪些可以使用

  MVC中的Handler方法可以接受ServletAPI类型的参数。

  009 使用servlet API作为参数

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.效果

  009 使用servlet API作为参数

5.ps

  Writer的由来

  response.getWriter();

相关文章