This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I have two servlets A and B. When a button in Servlet A has been clicked servlet B gets invoked. I have a string array in servlet A which I want to use in servlet B. Could anyone tell me how I can do it. Is it possible? Thanks Chak
Assuming both sevlets are in the same application, passing around objects like arrays of strings is what HttpSession objects are for. Incidently, saying something like: "When a button in Servlet A has been clicked servlet B gets invoked." represents sloppy thinking - servlet A may make a HTML page that has a button which can be clicked, but servlet A does not contain a button. You should always keep in mind that a servlet just gets a request and creates a response - any connection between repeated requests has to be created by the programmer. Bill
2 ways... 1. Before you get to servlet A is it possible to put this String in to the session...
Then get the array out of the session in servlet B.
2. You could try outputing the array into a hidden field in the page so that it gets submitted to servlet B. This is messy and a "bad practice" but it will work...usually. Hope this helps. [This message has been edited by Heath Lilley (edited August 21, 2001).]
Joined: Oct 20, 2000
Hi, Thanks for the reply and I am sorry it was a mistake to mention "When button in Servlet A..." I have another question. I have two servlets A and B. When a button in HTML page created by Servlet A has been clicked the control goes to another HTML page which contains a button, when clicked invokes servlet B. Now how can I make the control go from Servlet B to servlet A after the doPOst method is executed in Servlet B. The doPOST method in servlet B does a database operation. Can I add a statement at the end of doPOST method such that after executing the database operation the page created by servlet A gets displayed. Thanks Chak
Joined: Jan 09, 2001
I think i understand your question ... You want to direct the user to servlet A from servlet B. If this is what you want to do, you need to look at the following object.method.
You can send the request and response to any servlet/jsp you want by using this method...as long as the servlet/jsp is in the same web application.
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