- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/jsp/" />
- <property name="suffix" value=".jsp" />
- </bean>
其实InternalResourceViewResolver的工作很简单: 在视图逻辑名前面加上prefix,后面加上suffix;
- <bean id="myViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
- <property name="order" value="1"/>
- <property name="basename" value="views"/>
- </bean>
因为可以配置多个viewResolver,所以上面的resolver还有一个选项order, 标明优先级。
通过controller和直接访问jsp两种
我希望把用户可以直接访问的jsp放在 /jsp/ 下,把通过Controller才能访问的jsp放在/WEB-INF/jsp/下
Spring mvc 使用多种viewResolver的问题
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/WEB-INF/velo/"/> <property name= "velocityProperties"> <props> <prop key="input.encoding">utf-8</prop> <prop key="output.encoding">utf-8</prop> </props> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="cache" value="false"/> <property name="prefix" value=""/> <property name="suffix" value=".vm"/> <property name="contentType"><value>text/html;charset=UTF-8</value></property> <property name="exposeSpringMacroHelpers" value="true"/> <property name="order"><value>0</value></property> </bean> <bean id="JSPviewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="cache" value="false"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> <property name="contentType"><value>text/html;charset=UTF-8</value></property> <property name="order"><value>1</value></property> </bean>