springMVC支持多视图

参照博客 http://blog.csdn.net/z69183787/article/details/40426603

我只在springMVC-core.xml文件配置了两个视图也可以了

<!-- mvc:view-controller可以在不需要Controller处理request的情况,转向到设置的View -->
    <!-- 像下面这样设置,如果请求为/,则不通过controller,而直接解析为/index.jsp -->
    <mvc:view-controller path="/" view-name="index" />
    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        <!-- 配置jsp路径前缀 -->
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <!-- 配置URl后缀 -->
        <property name="suffix" value=".jsp"></property>
    </bean>
   
     <!-- 配置Velocity引擎 -->
    <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/WEB-INF/velocity/vm/"/>
        <property name="configLocation" value="classpath:velocity.properties"/>
    </bean>
    <!-- 配置Velocity视图解析器 -->
      <!-- VelocityViewResolver -->
   <bean id= "viewResolver"  class= "org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"> 
    <property name="cache" value="false"/>
        <property name="order" value="1"/>
        <property name="suffix" value=".vm"/>
        <property name="toolboxConfigLocation" value="WEB-INF/velocity/toolbox.xml"/>
        <property name="layoutUrl" value="layout/layout.vm" />
        <property name="contentType" value="text/html;charset=UTF-8"/>
         <property name="allowSessionOverride" value="true"/> 
         <property name="allowRequestOverride" value="true"/> 
         <property name="exposeSessionAttributes" value="true"/> 
         <property name="requestContextAttribute" value="rc"/> 
         <property name="exposeRequestAttributes" value="true"/>
    </bean>

猜你喜欢

转载自lintaozhou.iteye.com/blog/2324675