您的位置:首页 > 编程语言 > Java开发

SpringMVC的forward和redirect

2015-05-22 01:10 447 查看
package com.pas.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: