Access exception.class.name in spring: message tag when using SimpleMappingExceptionResolver

In several previous projects (all pre-Spring 3.0), I had a single jsp error handling file (usually "message.jsp") that had a line similar to the following:

<spring:message code="exceptions.${exception.class.name}" text="${exception.message}"/> 

This allowed me to display exceptions on this page and resolve certain localized error messages based on the type of exception, defining a derivative of SimpleMappingExceptionResolver:

 <bean id="exceptionMapping" class="mycode.ui.resolvers.MyExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">message</prop> <prop key="javax.servlet.ServletException">message</prop> <prop key="MyCustomException">message</prop> <prop key="ApplicationAuthorizationException">login</prop> <prop key="NotLoggedInException">login</prop> </props> </property> </bean> 

This worked flawlessly until I tried switching to Spring 3 and Tomcat 7. Now, when I use this code, I get the following error:

 "${exception.class.name}" contains invalid expression(s): javax.el.ELException: The identifier [class] is not a valid Java identifier as required by section 1.19 of the EL specification 

Any idea what has changed or how to access the name of the exception class (part of the model returned by Spring to the displayed error page)?

+6
source share
1 answer

The implementation of EL in Tomcat 7 has indeed been modified to prohibit Java keyword literals such as class , new , static , etc. as the properties of EL.

The only solution that is still available to access them, instead:

 ${exception['class'].name} 

See also Problem Tomcat 50147 .

+18
source

Source: https://habr.com/ru/post/889905/


All Articles