Servlet1 -------- response.sendRedirect("servlet/Servlet2"); ....... ....... ....... <FORM NAME=Servlet1 METHOD=POST ACTION=""> //FORM variables are present here..These form variables could not be retrieved from Servlet2 </FORM> .......
I can tell you what I do when writing servlets this way. Inside my servlet I make a private method. Now in my doPost or doGet, I take the request and response objects and forward them to wherever they need to go, based on parameters. For example, 'prepForPageTwo' would receive the request and response objects if the parameter page=Page2. Now the reason that I get the session is because sometimes I'll put some data into the session, so that the next page can see some of the things I come up with in the "//do some work here " section. Alternately, you can use req.setAttribute(obj, obj). And I have to use these, because unfortunately there is no such thing as request.setParameter() *you can't add parameters to the request that a servlet received and forward it to another resource.* But, you can add attributes which are just as good. In the code above, it would look like: It's not quite as nice as being able to 'setParameter' on the request, but it does the job.
I hope that helped.
Joined: May 15, 2001
Thanks Mike, Your suggestion was very useful for me. I had earlier tried using RequestDispatcher, but the Inprise App Server 4.1 from Borland complains this interface as error. Please find below the error message displayed on the browser. ---------------------------------------------------------------- 500 Internal Server Error The servlet named invoker at the requested URL http://rls/servlet/Realogic.ReportExecute reported this exception: java.lang.NoSuchMethodError. Please report this to the administrator of the web server. ---------------------------------------------------------------- I have another query to ask at this time. I am aware of the fact that we can use setAttribute on the request object and use getAttribute on a different page to get the value set. However, the Servlet2 code that I had mentioned in my earlier post is a 3rd party servlet. I just have the jar file for Servlet2 and I am not sure whether I can still use SetAttribute on my Servlet1. Any suggestions please. Thanks once again for your help.
I had a feeling that your second servlet would be 'black box'. You are right in suspecting that the 2nd servlet would require the form data to be in the QueryString, as opposed to in the Attributes.
If the 'additional' form elements don't depend on the values entered in the first form, then you can include them in the first form as hidden fields.
Joined: May 15, 2001
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com