gotjee
gotjee

Reputation: 43

JSP errorpage being inserted instead of forwarding?

While trying out some error-handling on JSP I noticed some strange behaviour.

The actual error will occur in the input of a form:

....
 <input type="hidden" id="INITIAL_ACTION" name="INITIAL_ACTION" value="<%=Myobject.myMethod()%>"/>
<input type="hidden" name="INITIAL_PAGE" ....

I see the content of my errorpage so the errorpage directive is working but the page doesn't look normal. Now when i look at the source of the page, it looks like the errorpage is actualy inserted into the value of this INITIAL_ACTION input on my previous page instead of being a forward:

...
        <input id="INITIAL_ACTION" type="hidden" value=" <html> <head> <title>ErrorPage</title> <link rel = 'stylesheet' type = 'text/css' href = '../css/newstyle.css' /> </head> <body> <div id=" name="INITIAL_ACTION"></input>
        <table class="borderedtable">

            <tbody>
                <tr> … </tr>
                <tr> … </tr>
    ...

Of course this is giving me some layout/css issues on the actual error-page. Could anyone please explain this behaviour or point me in the right direction?

Edit :

Increasing the page buffer works.

But this would be hard for my current application to identify which pages need this to make sure their error-handling works.

The problem was that the first double quoute of the id-attribute of the first DIV in the error page was used to close the value-attribute of the place where it was inserted..

at the top of the errorpage I have added a html-comment which contains a double quote + explanation.. Now that quote is used and the rest of the page is rendered fine.

But I don't realy like my solution, doesn't feel solid

Upvotes: 0

Views: 58

Answers (1)

Mark Thomas
Mark Thomas

Reputation: 16615

I'm guessing that you are using Apache Tomcat or one of the other JSP containers that uses Jasper (Tomcat's JSP engine) or a derivative of it.

If the response has already been committed when an error occurs, Jasper includes the error page rather than forwarding to it as that is the best it can do given the circumstances.

To forward to the error page you'll need to perform the action that triggers the error before the response is committed. Possible ways to do this include:

  • Increase the size of the page buffer so the response is committed later
  • Refactor the page so the code that triggers the error is executed earlier

Upvotes: 0

Related Questions