Tuesday, January 04, 2005

Struts mapping recap

Here is a sample stuts action mapping:-

<form-bean name="TestForm" type="com.test.form.TestForm">
<action path="/Test" parameter="action" type="com.test.action.TestAction" scope="request" validate="false" name="TestForm">
<forward name="list" path="/web/jsp/test.jsp" redirect="false">

The name parameter is what tells what is the form.
In the above the parameter action is what defines where the execution of the struts dispatch action will go to.
For example /Test?list will go a method called list in the Test Dispatch action.
There is only one forward above with the same name list, so mapping.findforward("list"), will forward to "/web/jsp/test.jsp". The redirect false will make sure that it is not redirected.

If it were to be redirect=true, the conatiner would forward the "/web/jsp/test.jsp" to the browser and then again asks the bowser to submit the same back to the server. Whatever test,jsp renders on screen after the submit of that test.jsp(which might have some form) would be visible. after that.

In short instead of just a forward to test.jsp , it forwards to test.jsp and then forces the browser to submit test.jsp again.

Internally this is done using two diffetent serlet api methods.

The forward is done using the requestdispatcher forward method

The redirect is done using the sendRedirect method of the http response object.

Needless to say whatever was there in the first request scope will be lost.One way to not loose pervious request data is the use of hidden variables back and forth but this can be very cumbersome.


Post a Comment

<< Home