Search code examples
httpexceptionerror-handlingstruts2struts

Handling error Pages in Struts 2


Whenever I enter the URL localhost:8443/context/anyname.anyextension I get the Status 404 (Not found) But when I try something like localhost:8443/context/anynameWithouthExtensions it seems that Struts 2 tries to map to an action and then I get the error 500 (Internal Server Error). Shouldn't I always get the status 404 with both approaches?


Solution

  • You have probably used a <default-action-ref , that is a reference to the default Action to be used for all the UN-matched requests for that namespace. And for that namespace, you have some rules specifying that only URLs without extensions are handled.

    Take a look at this:

    Docs: http://struts.apache.org/2.1.6/docs/action-configuration.html

    <package name="Hello" extends="action-default">
    
        <default-action-ref name="UnderConstruction">
    
        <action name="UnderConstruction">
            <result>/UnderConstruction.jsp</result>
        </action>
    

    and eventually post your configuration.

    If this is the case, i expect you got 404 even with a

    localhost:8443/context/SOME_INVENTED_PATH/anynameWithouthExtensions
    

    because the default action ref is probably bound only to the root.

    AND the default Action goes on error, of course...