标签:
HttpServletRequest Spring会自动将 Servlet API 作为参数传过来
HttpServletResponse
InputStream 相当于request,getInputStream() 获取请求区内容字节流
OutputStream 相当于request.getOutputStream() 获取响应区内容字节流
Reader request.getReader()
Writer request.getWriter()
注意InputStream/OutputStream不能与Reader/Writer混用
WebRequest 提供了统一的访问请求数据的接口(参数区、请求头区,但不能访问Cookie区)
NativeWebRequest 继承WebRequest,提供本地Servelt API
webRequest.getParameter(“test”)
webRequest.setAttribute(“key”,”value”,WebRequest.SCOPE_REQUEST);作用域范围
webRequest.getAttribute(“key”,WebRequest.SCOPE_REQUEST)
request = nativeWebRequest.getNativeRequest(HttpServletRequest.class)
response = nativeWebRequest.getNativeResponse(HttpServletResponse.class)
HttpSession
Spring MVC自动将Servlet API的session传递过来
命令对象
就是带有setter方法的普通类,用于接收表单参数
Map map, Model model, ModelMap modelMap
这三个参数能够暴露控制器中的模型,用于页面的数据渲染
@RequestMapping("exposeModelData.do") public String testExposeModelData(Map<String,String> map, Model model, ModelMap modelMap){ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"); Date date = new Date(); map.put("key1","value1"+dateFormat.format(date)); model.addAttribute("key2","value2"+dateFormat.format(date)); modelMap.addAttribute("key3","value3"+dateFormat.format(date)); return "exposeModelData"; }
<table> <thead><h2>显示控制器暴露的模型数据</h2></thead> <tbody> <tr> <td>Map</td> <td><c:out value="${key1}"/></td> </tr> <tr> <td>Model</td> <td><c:out value="${key2}"/></td> </tr> <tr> <td>ModelMap</td> <td><c:out value="${key3}"/></td> </tr> </tbody> </table>
页面上可以这样获取数据
标签:
原文地址:http://www.cnblogs.com/sherrykid/p/5789832.html