@RequestMapping("string1")
public String string1(){
System.out.println("有返回值,跳转到成功页面");
return "success";
}
@RequestMapping("string2")
public String string2(HttpServletRequest request, HttpServletResponse response){
System.out.println("有返回值,请求转发至成功页面");
return "forward:/WEB-INF/jsp/success.jsp";
}
@RequestMapping("string3")
public String string3(HttpServletRequest request, HttpServletResponse response){
System.out.println("有返回值,重定向到成功页面");
return "redirect:string2";
}
@RequestMapping("mv")
public ModelAndView mv (HttpServletRequest request, HttpServletResponse response) throws Exception{
response.sendRedirect("void1");
ModelAndView view = new ModelAndView();
view.setViewName("success");
System.out.println("返回modelandview");
return view;
}
@RequestMapping("void1")
public void Void1 (HttpServletRequest request, HttpServletResponse response) throws Exception{
request.getRequestDispatcher("/WEB-INF/jsp/success.jsp").forward(request,response);
System.out.println("没有返回值,请求转发到成功页面");
}
@RequestMapping("void2")
public void Void2 (HttpServletRequest request, HttpServletResponse response) throws Exception{
System.out.println("没有返回值,重定向到void1方法");
response.sendRedirect("void1");
}
@RequestMapping("void3")
public void Void3 (HttpServletRequest request, HttpServletResponse response) throws Exception{
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=utf-8");
response.getWriter().print("{id:1,username:张三,age:100}");
System.out.println("没有返回值,response直接输出数据");
}