Extend HttpHeaderResult to support HttpServletResponse.sendError()
------------------------------------------------------------------

                 Key: WW-1853
                 URL: https://issues.apache.org/struts/browse/WW-1853
             Project: Struts 2
          Issue Type: Improvement
          Components: Dispatch
    Affects Versions: 2.0.7, 2.0.6
            Reporter: Jasper Rosenberg


I had a need to have an action return a 404.  To do this, I extended the 
HttpHeaderResult class to accept an optional "errorCode" parameter which, if 
present, would trigger a response.sendError(errorCode).

Attached is my extension, but it probably should either be broken into its own 
result class, or properly merged into HttpHeaderResult itself.  Also, support 
should probably be added for an optional "errorMessage" so 
response.sendError(errorCode, errorMessage) can be invoked instead if an error 
message is available.

Here is a sample usage:

    <package name="default" extends="struts-default">
         <result-types>
             <result-type name="httperror" 
class="com.mycompany.struts2.result.ErrorSupportingHttpHeaderResult"/>
         </result-types>

        <global-results>
            <!-- 404 page result: not found. -->
            <result name="404" type="httperror">
              <param name="errorCode">404</param>
            </result>
        </global-results>
    </package>

Now I can have any action return "404" as the result and I will get a 404 page.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to