承接一二章
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>Hello World</title> <a href="springMVC/servletAPI">servletAPI</a> <br> <br> </body> </html>
tset.java
package com.hdxy.domian; import java.io.IOException; import java.io.Writer; import java.lang.reflect.Method; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import com.hdxy.pojo.User; @RequestMapping("springMVC") @Controller public class Test { /*可以使用serlvet 原生API作为目标方法的参数 具体支持以下类型 * * HttpServletRequest * HttpServletResponse * HttpSession * java.security.Principal * Locale * InputStream * OutputStream * Reader * Writer * * */ final public String SUCCESS="loginSuccess"; /* @RequestMapping(value="/servletAPI") public String servletAPI(HttpServletRequest requset,HttpServletResponse response){ System.out.println("servletAPI:"+requset); System.out.println("servletAPI:"+response); return SUCCESS; }*/ /* @RequestMapping(value="/servletAPI") public void Writer(Writer out){ try { out.write(SUCCESS); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }*/ @RequestMapping(value="/servletAPI") public void Writer(Writer out){ try { out.write("hello world"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }