Support both jsp and jspx in spring 3.0

柔情痞子 提交于 2019-12-19 03:58:52

问题


i've set up a roo application. The default view resolver built-in in roo is for jspx files. Is it possible to support also jsp files?. I tried configuring two viewResolvers but it seems that no urlBasedViewResolvers can coexist, its either one or the other.

Changing the order does not affect the behaviour. If I set order =1 to the jspx then if i search for any .jsp file it gives me 404. The same if I search for jspx but jsp viewResolver is set with order =1.

Is there anyway to do this? Thanks!

here is my webmvc-config.xml

<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="order" value="1"/>
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jspx" />
    </bean>
    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="order" value="2"/>
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

回答1:


One probably not a good solution that I can think of is to not provide a suffix, and to explicitly specify the .jsp or .jspx suffix when returning a view name.

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

and when returning a view name:

return "myview.jsp";
return "myview.jspx";

OR

Another solution if you know the name pattern for your jsp and jspx views names will be to provide the view names as one more parameter to one of the resolvers:

<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="order" value="2"/>
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value="jsp" />
    <property name="viewNames">
        <list>
    <value>view1*</view>
    <value>view2*</view>
    <value>view3*</view>
    </list>
    </property>
</bean>

If this viewresolver returns a null if it does not match any of the view patterns it would then go to your jspx view resolver.



来源:https://stackoverflow.com/questions/11603707/support-both-jsp-and-jspx-in-spring-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!