SpringMVC的forward和redirect

来源:互联网 发布:dbc2000数据库64位 编辑:程序博客网 时间:2024/06/14 04:59

package com.pas.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;@Controllerpublic class LoginController {@RequestMapping(value = "/forward.do")public String forward(@RequestParam("userName") String userName,@RequestParam("password") String password,@RequestParam("role") String role) {System.out.println("Login.....................................");return "index";//使用forward方式}@RequestMapping(value = "/redirect.do")public String redirect(@RequestParam("userName") String userName,@RequestParam("password") String password,@RequestParam("role") String role) {System.out.println("Login.....................................");return "redirect:index.jsp";//重定向方式}}


或者这种方式:
public ModelAndView login(@RequestParam("userName") String userName,@RequestParam("password") String password,@RequestParam("role") String role) {System.out.println("Login.....................................");ModelAndView view = null;if (StringUtils.equalsIgnoreCase("pandy", userName)&& StringUtils.equalsIgnoreCase("pandy", password)) {view = new ModelAndView(new RedirectView("index.jsp"));} else {view = new ModelAndView("../login");}return view;}
0 0
原创粉丝点击