HandlerInterceptorAdapter不会运行错误页面

时间:2014-07-17 14:58:59

标签: java spring-mvc exception exception-handling interceptor

有一个类,使用方法扩展HandlerInterceptorAdapter:

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
...
request.getSession().setAttribute("user", user);
}

除错误视图外,所有视图都可以看到此属性:(

My ExceptionConfiguration:

@Bean
public SimpleMappingExceptionResolver simpleMappingExceptionResolver(){
    SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver();

    Properties mappings = new Properties();
    mappings.setProperty("DatabaseException", "error/error");

    r.setExceptionMappings(mappings);
    r.setDefaultErrorView("error/defaultError");
    return r;
}

我的“错误/错误”页面:

<h3 th:text="${user.name}" />

<p><h3 th:text="${exception.message}" /></p>
<h3>Please contact support.</h3>

我的例外是:

org.springframework.web.util.NestedServletException: Request processing failed
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "user.name"    
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null

如何让属性'user'对错误页面可见?<​​/ p>

提前谢谢。

0 个答案:

没有答案