Explain about Inter-Servlet communication and business reason for using Inter-Servlet communication

Showing Answers 1 - 1 of 1 Answers

akantilal

  • Jun 12th, 2007
 

Inter-servlet communication can happen in the following ways:
1. By storing & retrieving data from shared scopes like session and application(servlet context).
2. By using forwards & redirects.

Method 1:

 If you have 2 servlets. In one servlet you do some calculation and store the data in session scope, for example bill for all the items in the user's shopping cart. Then you forward the request to another servlet which takes care of presenting the data to the user for confirmation before completing the order. This is just one scenario. There could be many more examples where you would need to store data in a shared scope in one servlet and retrieve it in another servlet.

Method 2:

 You would use this method, for example when you have a decision making servlet which forwards/redirects you to some other servlets depending on various conditions. For example, in the case of a shopping cart servlet, after the user confirms the order, if the order is successfully saved in the database, you redirect to a success page, otherwise to a failure page that shows the appropriate status.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions