ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
ModelAndView ~~~ @RequestMapping(value="/test3",method=RequestMethod.GET) public ModelAndView test3() { //跳转到index.jsp ModelAndView mav = new ModelAndView(); mav.addObject("msg", "hello test3"); mav.setViewName("/index.jsp"); //请求转发 return mav; } ~~~ String ~~~ @RequestMapping("/test5") public String test5(HttpServletRequest request) { request.setAttribute("msg", "hello test5"); return "/index.jsp";//请求转发 } ~~~ ~~~ @RequestMapping("/test6") public String test6(HttpSession session) { session.setAttribute("msg", "hello test6"); return "redirect:/index.jsp";//请求重定向 } ~~~ void ~~~ @RequestMapping("/ajax") public void test7(HttpServletResponse response) { response.setContentType("text/json"); response.setCharacterEncoding("utf-8"); try { PrintWriter out = response.getWriter(); out.write("{\"username\":\"feiyy\"}"); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ~~~ 对象类型(第四张ajax讲解) SpringMVC的依赖注入: HttpServletRequest request HttpSession session ServletContext application HttpServletResponse response Model model