|
From: Roberto C. <rob...@in...> - 2006-07-07 15:13:23
|
I agree with this but this responsibility is of the controller showing
the exception. Besides, if the exception resolver is used correctly, any
new exception will always replace the old one. Of course, if the users
navigates to the "error.html" page without having caused an exception ...
What I am more concerned about is the fact that if showing the exception
generates an exception which generates an exception which generates an
exception... you end up in a infinite redirect to the error.html page
There should be a way to intercept this recursive problem. Ideas?
/roberto
Erwin Vervaet wrote:
> One possible danger of putting exceptions in the session that I see is
> re-displaying 'old' errors. E.g. if for some reason the real exception isn't
> put in the session the error page will pick up on the previous exception
> that's still there. This can lead to very confusing situations.
> Ideally the exception in the session should be removed after it has been
> displayed to the user.
>
> Erwin Vervaet
> erw...@er...
> ----- Original Message -----
> From: "Roberto Cosenza" <rob...@in...>
> To: <spr...@li...>
> Sent: Friday, July 07, 2006 3:05 PM
> Subject: [Springframework-developer] SessionExceptionResolver
>
>
>> Hi.
>> I wrote a slightly different version of SimpleMappingExceptionResolver
>> which puts the exception in the http session instead of in the model. In
>> this way it is possible to use a redirect instead of a view and still be
>> able to access the exception to be shown to the user.
>> Using a redirect is usually better than a view since the flow of the
>> application after a redirect follows the normal execution of the program.
>> What do you think?
>> /Roberto
>>
>
>
> --------------------------------------------------------------------------------
>
>
>> package org.springframework.web.servlet.handler;
>>
>> import javax.servlet.http.HttpServletRequest;
>> import javax.servlet.http.HttpSession;
>>
>> import org.springframework.web.servlet.ModelAndView;
>>
>> /**
>> * Exception resolver that allows for mapping exception class names to view
>> * names as the SimpleMappingExceptionResolver. This resolver puts the
>> thrown
>> * exception in the HTTP session so that it can be retrieve later by a
>> * controller. Using this approach permits to use a redirect view when
>> handling
>> * the exception while stil having access to the originating exception.
>> *
>> * @author Roberto Cosenza
>> */
>>
>> public class SessionExceptionResolver extends
>> SimpleMappingExceptionResolver {
>>
>> public final static String DEFAULT_LATEST_EXCEPTION_KEY =
>> "SimpleMappingExceptionResolver.LATEST_EXCEPTION_KEY";
>> private boolean forceSession = false;
>> private String exceptionSessionKey = DEFAULT_LATEST_EXCEPTION_KEY;
>>
>> protected ModelAndView getModelAndView(String viewName, Exception ex,
>> HttpServletRequest request) {
>> logger.trace("getModelAndView");
>> HttpSession session = request.getSession(forceSession);
>> if (session != null) {
>> session.setAttribute(getExceptionSessionKey(), ex);
>> }
>> return new ModelAndView(viewName);
>> }
>>
>> /**
>> * Tells if the session must be created if not already existing
>> *
>> * @return default is false
>> */
>> public boolean isForceSession() {
>> return forceSession;
>> }
>>
>> public void setForceSession(boolean forceSession) {
>> this.forceSession = forceSession;
>> }
>>
>> public String getExceptionSessionKey() {
>> return exceptionSessionKey;
>> }
>>
>> public void setExceptionSessionKey(String excepionSessionKey) {
>> this.exceptionSessionKey = excepionSessionKey;
>> }
>> }
>>
>
>
> --------------------------------------------------------------------------------
>
>
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your job
>> easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>
>
>
> --------------------------------------------------------------------------------
>
>
>> _______________________________________________
>> Springframework-developer mailing list
>> Spr...@li...
>> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
Roberto Cosenza
Infoflex Connect AB, Sweden
Tel: +46-(0)8-55576867, Fax: +46-(0)8-55576861
--
Nordic Messaging Technologies is a trademark of Infoflex Connect.
Please visit www.nordicmessaging.se for more information about our
carrier-grade messaging products.
|