SpringMVC redireccionamiento hacia adelante

Uno hacia adelante

. 1  @Controller
 2  pública  clase Modeltest {
 . 3      @RequestMapping ( " / T1 " ) // dirección del acceso URL   http: // localhost : 8080 / springmvc_04_controller01_war_exploded / T1 
. 4      pública Cadena Test (el Modelo de Modelo) {
 . 5          model.addAttribute ( " MSG " , " test.jsp bajo jsp " );
 6          / * el reenvío de reenvío se usa por defecto * / 
7          return  " /WEB-INF/jsp/test.jsp " ;
 8      }
 9 }

Adelante dos

1  @Controller
 2  pública  clase ModelTest {
 3      @RequestMapping ( " / t1 " ) // url访问的地址   http: // localhost : 8080 / springmvc_04_controller01_war_exploded / T1 
4      pública prueba de la cuerda (modelo Modelo) {
 5          model.addAttribute ( " msg " , " jsp test 的 test.jsp " );
6          / * 在 WEB-INF 加 adelante 转发* / 
7          return  " adelante: /WEB-INF/jsp/test.jsp " ;
8      }
 9 }

Redirigir

. 1  @Controller
 2  pública  clase Modeltest {
 . 3      @RequestMapping ( " / T1 " ) // dirección URL para acceder 
. 4      público Cadena la Prueba (el modelo Model) {
 . 5          model.addAttribute ( " MSG " , " test.jsp bajo JSP " ) ;
 6          / * redirect * / 
7          return  " redirect: /index.jsp " ;
 8      }
 9  }
 10 Los recursos de WEB-INF no se pueden redirigir

 

configuración web

1 <? Xml version = " 1.0 " encoding = " UTF-8 " ?>
 2 <web-app xmlns = " http://xmlns.jcp.org/xml/ns/javaee " 
3           xmlns: xsi = " http: //www.w3.org/2001/XMLSchema-instance " 
4           xsi: schemaLocation = " http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee /web-app_4_0.xsd " 
5           version = " 4.0 " >
 6      <servlet>
 7          <servlet-name> springmvc <
/ nombre-servlet> 8         <servlet- class > org.springframework.web.servlet.DispatcherServlet </ servlet- class >
 9          
10          <init-param>
 11              <param-name> contextConfigLocation </param-name>
 12              <param-value> classpath: springmvc- servlet.xml </param-value>
 13          </init-param>
 14      </servlet>
 15      <servlet-mapping>
 16          <servlet-name> springmvc </servlet-name>
 17          <url-pattern> / </ url -pattern>
 18      </servlet-mapping>
 19  
20 </web-app>

springmvc-servlet.xml

1 <? Xml version = " 1.0 " encoding = " UTF-8 " ?>
 2 <beans xmlns = " http://www.springframework.org/schema/beans " 
3         xmlns: xsi = " http: // www. w3.org/2001/XMLSchema-instance " 
4         xmlns: context = " http://www.springframework.org/schema/context " 
5         xmlns: mvc = " http://www.springframework.org/schema/mvc " 
6         xsi: schemaLocation = " http: //www.springframework.org / schema / beans 
7          https:// www.springframework.org/schema/beans/spring-beans.xsd 
8          http: // www.springframework.org/schema/context 
9          http: // www.springframework.org/schema/context/spring-context. xsd 
10          http: // www.springframework.org/schema/mvc 
11          http: // www.springframework.org/schema/mvc/spring-mvc.xsd "> 
12      <! - Open note->
 13      <context : componente-scan base -package = " com.rzk.controller " />
 14      <! - Filtrar recursos estáticos->
 15      <mvc:default -servlet-handler />
 16      <! - Omitir procesador, mapeador      Adaptador- >
 17 <mvc: impulsado por anotaciones />
 18  
19 </ beans>

 

Lo anterior es sin una resolución de vista

 

analizador de vista de configuración springmvc-servlet.xml

1 <? Xml version = " 1.0 " encoding = " UTF-8 " ?>
 2 <beans xmlns = " http://www.springframework.org/schema/beans " 
3         xmlns: xsi = " http: // www. w3.org/2001/XMLSchema-instance " 
4         xmlns: context = " http://www.springframework.org/schema/context " 
5         xmlns: mvc = " http://www.springframework.org/schema/mvc " 
6         xsi: schemaLocation = " http: //www.springframework.org / schema / beans 
7          https:// www.springframework.org/schema/beans/spring-beans.xsd 
8          http: // www.springframework.org/schema/context 
9          http: // www.springframework.org/schema/context/spring-context. xsd 
10          http: // www.springframework.org/schema/mvc 
11          http: // www.springframework.org/schema/mvc/spring-mvc.xsd "> 
12      <! - Open note->
 13      <context : componente-scan base -package = " com.rzk.controller " />
 14      <! - Filtrar recursos estáticos->
 15      <mvc:default -servlet-handler />
 16      <! - Omitir procesador, mapeador      Adaptador- >
 17 <mvc: impulsado por anotaciones />
 18  
19 <! - & lt ;! & ndash; Ver resolver & ndash; & gt; ->
 20      <bean class = " org.springframework.web.servlet.view.InternalResourceViewResolver " 
21            id = " InternalResourceViewResolver " >
 22          <! - prefix- >
 23          <property name = " prefix " value = " / WEB-INF / jsp / " />
24          <! - Sufijo->
 25         <property name = " suffix " value = " .jsp " />
 26      </bean>
 27  
28 </beans>

Intente la redirección primero

1  @Controller
 2  pública  clase ModelTest {
 3      @RequestMapping ( " / t1 " ) // url访问的地址
4      pública prueba de la cuerda (modelo Modelo) {
 5          model.addAttribute ( " msg " , " JSP下的test.jsp " ) ;
6          / * redirect * / 
7          return  " redirect: /index.jsp " ;
8      }
 9 }

 

 Se puede acceder a él, y la resolución de vista también se usa de la misma manera.

 

Intente reenviar con view resolver nuevamente

1  @Controller
 2  pública  clase ModelTest {
 3      @RequestMapping ( " / t1 " ) // url访问的地址
4      pública prueba de la cuerda (modelo Model) {
 5          model.addAttribute ( " msg " , " índice " );
6          / * redirect * / 
7          return  " index " ;
8      }
 9 }

 

Supongo que te gusta

Origin www.cnblogs.com/rzkwz/p/12732875.html
Recomendado
Clasificación