Home.java:
package com.shuoeasy.springmvc; 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; @RequestMapping("/home")// 修饰类 @Controller public class Home { /** * 支持Servlet 原生的API作为目标方法的参数 * 支持如下 * HttpServletRequest * HttpServletResponse * HttpSession * java.security.Principal * Locale InputStream * OutputStream * Reader * Writer * * 路径 : home/show */ @RequestMapping("/show") public String showPage(HttpServletRequest request, HttpServletResponse response){ System.out.println("request=" + request + ",response=" + response); return "home_index"; } /** * 支持Servlet 原生的API作为目标方法的参数 * @param request * @param response * @param writer * @throws IOException */ @RequestMapping("/show2") public void showPage2( HttpServletRequest request, HttpServletResponse response, Writer writer) throws IOException{ writer.write("shuoeasy.com"); // 页面输出: shuoeasy.com } }