|
From: Erwin V. <erw...@er...> - 2006-07-07 13:26:26
|
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
>
|