如何在Spring/MVC 3.0应用程序中使用带有磁贴的常见错误页面模板? [英] How do I have common error page templates with tiles in a Spring/MVC 3.0 app?

查看:97
本文介绍了如何在Spring/MVC 3.0应用程序中使用带有磁贴的常见错误页面模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring MVC/3.0应用程序,它使用瓦片作为视图,这很好,但是我不知道如何获取错误页面以同时使用瓦片.

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.

我在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.

该视图的tiles.xml文件包含以下定义

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>

我正在通过Spring配置磁贴,如下所示:

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.xml中添加布局的" jsp.下面是解释代码:

You need to add the "layouted" jsp in your web.xml. Below is the explaination code:

// Your web.xml should look like this:
<error-page>
  <error-code>404</error-code>
  <location>/WEB-INF/error/layout-404.jsp</location>
</error-page>


// Your layout-404.jsp should look like this:
<%@page isELIgnored="false" %>
<%@page contentType="text/html"%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insertDefinition name="404" />    


// Your layout def should look like this:
<definition name="404" extends="standardLayout">
  <put-attribute name="body" value="/WEB-INF/error/404.jsp" />
</definition>

这篇关于如何在Spring/MVC 3.0应用程序中使用带有磁贴的常见错误页面模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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