SpringMVC small problem in the redirect and forward the request to forward the URL path

In SpringMVC forward the request, we first have the following code

@Controller
public class chekController {
	@Autowired
	private IEmployeeDAO dao;
	@RequestMapping("/check")
	public String check(Employee e,HttpSession session) {
		Employee em = dao.login(e.getUsername(), e.getPassword());
		if(em!=null) {
			session.setAttribute("USER_IN_SESSION", e);
			return "redirect:/list";
		}
}
    @RequestMapping("/list")
    public String list(Model m) {
	   List<Employee> list = dao.listAll();
	   m.addAttribute("em",list);
	   return "employee/list";
   }
}

We know that if the return statement written return "list"; documents that enter the view resolver to add prefix and suffix to find the corresponding 

This is my view resolver ↑

Finally become /WEB-INF/views/list.jsp

But if the return is the way forward request it?

FIG e.g. on the return "redirect: / list";

In use the redirect mode return or forward mode ( return "forward: / List"; ) will not enter the parser parses the view, but rather a request forwarded by way of the transmission. And this case was divided into two ①return "redirect: / list"; ②return "redirect: /list.jsp";

The first embodiment will be redirected to the controller @RequestMapping ( "/ list") corresponding to a processor for processing (above code)

The second way, it will enter webapp / root directory of the file to look for and respond to a list.jsp

Similarly way forward

Released six original articles · won praise 3 · Views 792

Guess you like

Origin blog.csdn.net/SmileLucki/article/details/105379648