如何在 Spring/MVC 3.0 应用程序中使用带有图块的常见错误页面模板?
我有一个使用图块作为视图的 Spring MVC/3.0 应用程序,这工作正常,但是我不知道如何让错误页面也使用图块。
我在我的 web.xml
中,
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
它可以作为不使用图块的普通视图正常工作,但是当我将位置更改为视图名称之一时,找不到该视图并呈现普通错误页面。
我的视图 tiles.xml
文件包含以下定义,
<definition name="404" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/error/404.jsp" />
</definition>
我正在通过 spring 配置图块,如下所示:
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/**/tiles.xml</value>
</list>
</property>
</bean>
我怀疑这都是由于视图不是来自 spring 本身?
I have a Spring MVC/3.0 app using tiles as it's view, this is working fine however I can't figure out how to get the error pages to also use tiles.
I have in my web.xml
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
which works fine as an ordinary view NOT using tiles, however when I change the location to one of the view names, the view is not found and renders the ordinary error page.
My tiles.xml
file for the view contains the following definition
<definition name="404" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/error/404.jsp" />
</definition>
I'm configuring tiles through spring as follows:
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/**/tiles.xml</value>
</list>
</property>
</bean>
I'm suspecting this is all due to the view not coming from spring itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在 web.xml 中添加“布局”jsp。下面是解释代码:
You need to add the "layouted" jsp in your web.xml. Below is the explaination code:
在tiles中定义错误模板会更简单:
并使用Spring MVC处理它,例如:
在这种情况下,您不必将错误页面添加到web.xml中,每个错误页面一个.jsp文件就足够了。
It would be just simpler to define error template in tiles:
And handle that with Spring MVC, e.g.:
In this case, you don't have to add error pages to your web.xml, and one .jsp file per error page will suffice.