springmvc将数据设置到request作用域

方法一:利用ModelMap

@RequestMapping(value="/hello.action", method=RequestMethod.GET)

 public String hello(String id, ModelMap model) {

  model.put("id", id);

  return "hello";

 }

方法二:声明一个map对象作为参数就可

@RequestMapping(value="/person.action")

 public String person(Map<String, Object> model) {

  model.put("id", "001");

  return "person";

 }

页面el表达式获取值:

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 ${ id}
</body>
</html>

你可能感兴趣的:(springMVC,request)