in Spring MVC, when we return to the logical view, the framework parses the specific view with viewresolver and renders it to the browser. Assuming that the logical view is named Hello, through configuration, we Configure a viewresolver as follows:
<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <description> If the logic tries to name "Hello", Viewresolver will parse into/web-inf/jsp/hello.jsp </description> <property name= " Order "value="/> <property name= "prefix" value= "/web-inf/jsp/"/> <property name= "suffix" Value= ". jsp"/> </bean>
in fact, the framework is forwarded to the/web-inf/jsp/hello.jsp by means of forward. If the logical view name is/hello, it is actually forwarded to/web-inf/jsp/hello.jsp, that is,/web-inf/jsp//hello.jsp is equivalent to/web-inf/jsp/hello.jsp.
Now there is a problem, if/hello is a controller mapping, I want to forward to this controller, how to do? We can pass
forward prefix to achieve the purpose of forwarding to other resources:
Public String handle () { //return "Forward:/hello" = + forwards to controller capable of matching/hello //return "Hello" = actual On or forward, except that the framework will find the view with the logical views name and render //return "/hello" + = with return "Hello" return "Forward:/hello"; }
Similarly, if we want to redirect to a resource, we can
redirect prefix to achieve the purpose of redirection to other resources:
Public String handle () { //Redirect to/hello resource return ' Redirect:/hello '; }
Summary: When you want to jump between controller mapping requestmapping, be sure to prefix: foward or redirect
Otherwise, the return is only interpreted as a view.
Do not know whether the summary is correct, the wrong words, hope to point out, perfect, so as to learn
Springmvc foward and redirect Jump simple analysis