1: respose:
index2.jsp 在webContent目录下
resp.sendRedirect("../index2.jsp");
2: request:
request.setAttribute("name", "ftian");
request.getRequestDispatcher("../index2.jsp").forward(request, resp);
页面EL表达式取值:
<body>
<h1>hello world12345!</h1>
name:${requestScope.name }
</body>
3:ModelAndView
public ModelAndView testJson(HttpServletRequest request,HttpServletResponse resp) throws Exception, IOException{
String name = request.getParameter("name");
System.out.println("name:"+name);
Map<String,Object> map = new HashMap<String,Object>();
map.put("ok","okjson");
String json = JSON.toJSONString(map);
System.out.println("json:"+json);
//resp.getWriter().println("hello HttpServletResponse");
//resp.sendRedirect("../index2.jsp");
// request.setAttribute("name", "ftian");
// request.getRequestDispatcher("../index2.jsp").forward(request, resp);
ModelAndView mv = new ModelAndView();
mv.addObject("name","beijing");
mv.setViewName("index2");//跳转到jsp的名称index2.jsp 目录为web-info
return mv;
}
页面EL表达式取值:
<body>
<h1>hello world12345!</h1>
name:${requestScope.name }
</body>