How to Pass Array from One Servlet to Another Servlet?

I want to pass multiple values from one servlet to another one servlet. Please tell me how to pass that?


Depending if you use sessions:

  1. Store the array in the session variable using session.setAttribute();
  2. Retrieve the array using session.getAttribute();

However the variable will stay until the session dies, you overwrite it with something else, or you remove it.

If you forward one servlet to another servlet, you can store it in the request variable:

  1. request.setAttribute()

Which you can read after forwarding using request.getAttribute() after calling


Note this does not work if you're doing a redirect instead of a servlet forward.

You can

  • put your array in request context as an attribute using request.setAttribute()
  • forward the request to second servlet using RequestDispatcher.forward()
  • in your second servlet read the value using request.getAttribute()

You can store the array in the user session in servlet 1 and read it from servlet 2 getting it from the user session. Make sure you delete the array from session in servlet 2.

Need Your Help

Why is there a rough black edge when rounding corner of UIButton?

ios objective-c uibutton uiimage

I'm adding a UIButton (with background image) to the navigation bar and setting rounded corners with a border. I'm getting a strange black outline on the corners:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.