JavaExample.net | Default struts 2 action

We can define through struts.xml an action that response when we get an unavailable resource

For example if we get http://localhost:8080/helloworld  but helloworldAction doesn’t exist generally we obtain an 404 error

Using following configuration

 
<default-action-ref name="home" />
 
<global-results>
			<result name="success">/jsp/main.jsp</result>
			<result name="login" type="redirect">/login.html</result>
			<result name="error" type="redirect">/404.html</result>
		</global-results>
 
		<global-exception-mappings>
			<exception-mapping exception="java.lang.Throwable"
				result="error" />
		</global-exception-mappings>

In this way when we get an unavailable resource the framework run the home action as default

Share →

Leave a Reply

Your email address will not be published. Required fields are marked *