springmvc 与jsp传值

来源:互联网 发布:node输出pdf 编辑:程序博客网 时间:2024/05/18 20:10

除了request.getparameter外,还有以下方法

1,model  map中保存key,value

如:

@RequestMapping("/getAgent")
public String getAgentById(HttpServletRequest req,Map<String,Object> map){
log.info("进入getAgentById");
Agent agent=agentService.getAgentById("123");
log.info(agent.toString());
req.setAttribute("name", agent.getName());
req.setAttribute("id", agent.getAgentId());
map.put("agentt", agent);
//mo.addAttribute("agen", agent);
//mo.addAttribute("greetings", "I came from Model not ModelAttribute");
return "getResult";
}


jsp页面如下:

<body>
hello world!
<%--
<c:forEach items="${agent}" var="p">
<p>agentId:${p.agentId}</p>
<p>companyCode:${p.companyCode}</p>
<p>loginName:${p.loginName}</p>
<p>name:${p.name}</p>
</c:forEach>
--%> 
<p>
<c:out value="${greetings}" />
</p>
<p>${greetings}</p>

<p>${agentt}</p>
<p>${agentt.name}</p>


显示结果如下:

hello world!

Agent [agentId=123, companyCode=456, loginName=zzz, name=周周周]

周周周


0 0