SpringMvc 页面跳转
来源:互联网 发布:逆袭网络剧第一集 编辑:程序博客网 时间:2024/06/06 06:29
----1、使用HttpServletRequest request,HttpServletResponse response 进行页面跳转
// 转发页面带参数 @RequestMapping("/resp") public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception { req.setAttribute("message","it's forword "); req.getRequestDispatcher("index.jsp").forward(req,resp); }
// 重定向 @RequestMapping("/resp") public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception { resp.sendRedirect("index.jsp"); }
----2、在springmvc中 在进行配置视图解析器后,
<!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/page"></property> <property name="suffix" value=".jsp"></property> </bean>
1)、 return "index"; -----直接返回/page/index.jsp 页面
2)、 在方法上加@ResponseBody 或 使用@RestContorller , return "index"; 就会直接变成json字符串返回给浏览器
3)、转向 ,返回页面并带参数
--ModelMappublic String login(String name,String pass ,ModelMap model){ User user = userService.login(name,pwd); model.addAttribute("user",user); model.put("name",name); return "success"; //success.jsp } --ModelAndViewpublic ModelAndView toAddUser(HttpServletRequest request,ModelAndView mv){ ModelAndView mv = new ModelAndView(); mv.setViewName("index"); //跳转页面 Map map = new HashMap(); mv.addObject("map", map); return mv;}4)、重定向
1)、return "redirect:/ toList "; ----不带参数2)、使用RedirectAttributes 带参数 public String save(@ModelAttribute("form") Bean form,RedirectAttributes attr) throws Exception { String code = service.save(form); attr.addFlashAttribute("name", form.getName()); attr.addFlashAttribute("success", "添加成功!"); return "redirect:/index";
阅读全文
0 0
- SpringMVC的页面跳转
- springMVC 跳转到页面
- SpringMvc 页面跳转
- SpringMVC controller控制页面跳转
- 页面跳转,js和SpringMVC
- springmvc跳转页面的方法
- SpringMVC—ParameterizableViewController控制器实现跳转页面
- SpringMVC—UrlFilenameViewController控制器实现跳转页面
- EasyUI+SpringMVC配置session过期跳转页面
- springMVC 几种页面跳转方式
- SpringMVC注解及实现页面跳转详解
- springMVC提交form表单页面不跳转
- SpringMVC拦截器之拦截跳转页面
- Springmvc几种页面跳转的方式
- springMVC 几种页面跳转方式
- springMVC 几种页面跳转方式
- redirect springmvc中指定页面跳转方式
- springMVC 几种页面跳转方式
- HADOOP1.X中HDFS工作原理
- 23_File类递归练习
- 习题3.1(2)
- 统计每年每月的信息
- 滚粗了,拜拜
- SpringMvc 页面跳转
- [51Nod 2026] Gcd and Lcm
- 24_多线程
- C语言编写三子棋完整代码(分三个文件)
- jenkins构建Docker 镜像(基于Jenkins的Docker镜像及Jenkins插件)
- stack
- Vmware下CentOS7最小化安装
- Java8新特性
- window下的Python 环境配置