如何在spring mvc3中显示tiles2.tilesview
我一直在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里是设置 Tiles 所需的内容(我假设您使用的是 Tiles 2)
1° 步骤
定义 TilesConfigurer
2° 步骤
设置视图解析器(您可以使用 UrlBasedViewResolver或ResourceBundleViewResolver)。但请记住,无论您是否使用 UrlBasedViewResolver,Spring不允许您使用其他 UrlBasedViewResolver 子类,例如 InternalResourceView、VelocityView 和 FreeMarkerView。
或者
或者
这里是 view.properties 的一些代码
Here goes what you need to set up Tiles (I suppose you are using Tiles 2)
1º step
Define a TilesConfigurer
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
Or
Here goes some piece of code of view.properties