在Spring 3.0中同时支持jsp和jspx [英] Support both jsp and jspx in spring 3.0

查看:127
本文介绍了在Spring 3.0中同时支持jsp和jspx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个roo应用程序.内置在roo中的默认视图解析器用于jspx文件.是否可以同时支持jsp文件?我尝试配置两个viewResolvers,但似乎没有urlBasedViewResolvers可以共存,一个或另一个都可以.

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.

更改顺序不会影响行为.如果我将jspx设置为order = 1,那么如果我搜索任何.jsp文件,它将得到404.如果我搜索jspx,但jsp viewResolver设置为order = 1,则结果相同.

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!

这是我的webmvc-config.xml

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>

推荐答案

我可能想到的一个不好的解决方案是不提供后缀,并在返回视图时显式指定.jsp或.jspx后缀名称.

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>

以及返回视图名称时:

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

OR

如果您知道jsp和jspx视图名称的名称模式,另一种解决方案是将视图名称作为一个参数提供给解析器之一:

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>

如果此viewresolver如果不匹配任何视图模式,则返回null,然后将其转到jspx视图解析器.

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.

这篇关于在Spring 3.0中同时支持jsp和jspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆