Avatar billede fredand Forsker
13. oktober 2010 - 12:42 Der er 1 løsning

Problems understand error handling in struts-config.xml vs web.xml?

Hello!

I hope I explain this problem in an informative way.

And at the end I got two questions.

We got an webapp that uses struts 1.2.4

In our web.xml we got:
<error-page>
  <exception-type>java.lang.Throwable</exception-type>
  <location>/pages/systemfelStruts.jsp</location>
</error-page>

In our struts-config.xml we got this config for an Action:

  <action input=".theInput" name="inputForm" path="/resultatAction" scope="request" type="se.ResultatAction">
  <forward name="success" path=".resultatAction" redirect="false"/>
  <forward name="error" path="/start.do" redirect="false"/>
  </action>

The action looks like

public class ResultatAction extends SuperAction
{
 
 
  public ActionForward doExecute(
      ActionMapping pMapping,
      ActionForm pForm,
      HttpServletRequest pRequest,
      HttpServletResponse pResponse)
  throws Exception
  {
 
      if(1==1)
      {
          throw new ExceptionDTO(1);
      }
      return pMapping.findForward("success")
  }
}

As you can see above the ResultAction will never return success since it throws an ExceptionDTO that extends from Exception

The SuperAction looks like:

public abstract class SuperAction extends Action
{


    public ActionForward execute(
    ActionMapping pMapping,
    ActionForm pForm,
    HttpServletRequest pRequest,
    HttpServletResponse pResponse)
    throws Exception
    {

    try
    {
            return doExecute(pMapping, pForm, pRequest, pResponse);
    }
    catch (ExceptionDTO e)
    {
            pRequest.setAttribute(STATUS_CODE, null);
            pRequest.setAttribute(EXCEPTION_TYPE, e.getClass().getName());
            pRequest.setAttribute(MESSAGE, "\n" + e.getMessage());
            pRequest.setAttribute(WebUtils.EXCEPTION, e);
            pRequest.setAttribute(WebUtils.REQUEST_URI, pRequest.getRequestURI());
            ActionForward actionForward = pMapping.findForward(ActionStrings.ERROR);
            return actionForward;
    }
    }
}


Most of the first time we access ResultatAction we get the systemfelStruts.jsp returned when we get to the catch in SuperAction but!
The second time and all times after that we get the correct error mapping specified in struts-config.xml

1)
Why is that?
Is this because the error mapping is not initiated and then the struts-framework fall back to settings inside web.xml?
Is there a way to in advance initiate the error mapping from struts-config.xml?

2)
An second drawback is also that when the error mapping is returned correct, it looks like the settings from web.xml also tries to display the error-page since we get:

12:22:15,157 ERROR [[localhost]] Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/pages/systemfelStruts.jsp]
java.lang.IllegalStateException: Cannot reset buffer after response has been committed
        at org.apache.catalina.connector.Response.resetBuffer(Response.java:684)
       
Is there a way to prevent the systemfelStruts.jsp to be displayed if for example response.isCommited()?


All responses is most welcome!!!

Best regards
Fredrik
Avatar billede fredand Forsker
29. december 2010 - 21:58 #1
Do not like struts!
Closing since old!
/Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester