Controller类
public class HelloWorldController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
System.out.println("-----test-----");
//传递字符串数据
String hello = "hellow World! 欢迎";
return new ModelAndView("/welcome","result",hello);
/* 传递一个map类型数据
Map<String,Object> map = new HashMap<String,Object>();
for(int i = 0;i<5;i++){
map.put(Integer.toString(i), i);
}
return new ModelAndView("/welcome","map",map);
*/
}
}
接收数据的页面:welcome.jsp
<body>
<h1>传输数据</h1>
用EL表达式获取数据:${result};
如果是遍历传递数据,用<c:forEach>标签(需要导入jstl.jar)
<c:forEach item="${map }" var="m">
${m.key}--->${m.value};
<c:forEach>
</body>