简体   繁体   中英

How to use spring internalResourceviewresolver muliple times in spring mvc xml file

How to use spring InternalResourceViewResolver multiple times in spring mvc xml file?

I defined in WEB-INF 4 folders, containing jsps, like admin, user, developer, tester but in spring mvc xml file using single InternalResourceViewResolver and single folder.

Example

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix"><value>/WEB-INF/admin/</value></property>
    <property name="suffix"><value>.jsp</value></property>
</bean>

You cannot use InternalResourcerViewResolver multiple times in Spring xml.

Instead put all your jsp files into views folder(any folder), and from the controller, call which page you want to go.

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix"><value>/WEB-INF/views/</value></property>
    <property name="suffix"><value>.jsp</value></property>
</bean>

The return ModelAndView or return will come to spring xml with "jsp file name" it will identify according to your property in the xml and it will go to appropriate jsp page.

您可以尝试这样:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM