如何在spring mvc3中显示tiles2.tilesview

发布于 2024-09-08 09:37:08 字数 1950 浏览 3 评论 0原文

我一直在尝试使用 UrlBasedViewResolver 渲染图块视图几个小时。谁能告诉我它是如何完成的。我通常会尝试解决这个问题

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"></property>
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
    <property name="order" value="1"/>              
</bean> 


<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="basename" value="views"/>
    <property name="order" value="0"/>
</bean>

,在我的views.properties 文件中,我会有其他视图路径,这些路径将由jstlView 呈现。这是一个例外,

javax.servlet.ServletException: Could not resolve view with name 'welcome' in servlet with name 'epub'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1042)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

但它给出的结果是行不通的。它说它无法渲染视图。我知道这不是因为链接 2 个视图解析器,也不是因为tilesconf。因为当我在 view.properties 文件中定义tile的视图类时它就会起作用。所以我假设 urlbasedviewresolver 和tilesview 在某些方面不能一起工作。我将有很多图块布局,因此在属性文件中定义所有这些布局并不是很美观。(我将有很少的常规 jsp 页面,因此可以使用 resourceBundleViewResolver)有什么想法吗?

I have been trying to render tiles view with UrlBasedViewResolver for hours. Can anybody show me how it's done. I generally am trying to work this out

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"></property>
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
    <property name="order" value="1"/>              
</bean> 


<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="basename" value="views"/>
    <property name="order" value="0"/>
</bean>

and in my views.properties file, I would have my other view paths which would be rendered by jstlView. here is the exception it's giving

javax.servlet.ServletException: Could not resolve view with name 'welcome' in servlet with name 'epub'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1042)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

this just wouldn't work though. It says that it can't render the view. I know it's not because of chaining 2 view resolvers and not because of tiles conf either. Because when I define tile's view class in view.properties file it would work. So I assume that urlbasedviewresolver and tilesview can't work together in some ways. I will have a lot of tile layouts so it's not really beautiful to define all of them in my properties file.(I will have few regular jsp pages so it's ok to use resourceBundleViewResolver) Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一绘本一梦想 2024-09-15 09:37:08

这里是设置 Tiles 所需的内容(我假设您使用的是 Tiles 2)

1° 步骤

定义 TilesConfigurer

<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <!--Set up your Tiles definition RIGHT HERE-->    
            <value>/WEB-INF/defs/general.xml</value>
        </list>
    </property>
</bean>

2° 步骤

设置视图解析器(您可以使用 UrlBasedViewResolver或ResourceBundleViewResolver)。但请记住,无论您是否使用 UrlBasedViewResolver,Spring不允许您使用其他 UrlBasedViewResolver 子类,例如 InternalResourceView、VelocityView 和 FreeMarkerView。

或者

<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <!--Tiles IS NOT JSP-->
    <!--So you can not use JSP stuffs like .jsp suffix-->
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>

或者

<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <!--views.properties is located in The root of the classpath-->
    <property name="basename" value="views"/>
</bean>

这里是 view.properties 的一些代码

#You MUST SET UP each Target view class
welcome.(class)=org.springframework.web.servlet.view.tiles2.TilesView
#url MUST MATCH Tiles definition 
welcome.url=welcome

Here goes what you need to set up Tiles (I suppose you are using Tiles 2)

1º step

Define a TilesConfigurer

<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <!--Set up your Tiles definition RIGHT HERE-->    
            <value>/WEB-INF/defs/general.xml</value>
        </list>
    </property>
</bean>

2º step

Set up your view resolver (You can use Either UrlBasedViewResolver Or ResourceBundleViewResolver). But keep in mind whether you use UrlBasedViewResolver, Spring does not allow you use other UrlBasedViewResolver subclass, such as InternalResourceView, VelocityView and FreeMarkerView.

Either

<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <!--Tiles IS NOT JSP-->
    <!--So you can not use JSP stuffs like .jsp suffix-->
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>

Or

<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <!--views.properties is located in The root of the classpath-->
    <property name="basename" value="views"/>
</bean>

Here goes some piece of code of view.properties

#You MUST SET UP each Target view class
welcome.(class)=org.springframework.web.servlet.view.tiles2.TilesView
#url MUST MATCH Tiles definition 
welcome.url=welcome
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文