This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Passing ArrayList from JSP to Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing ArrayList from JSP to Servlet" Watch "Passing ArrayList from JSP to Servlet" New topic
Author

Passing ArrayList from JSP to Servlet

karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

Hi all,

I need to pass Arraylist from a jsp to my Handler class via Servlet . I can't use session since my handler class creates new session everytime . How could i achieve it ...

This requirement is for pagination.. I populate arrayList values in my Data class using a web service call. I return those list back to Jsp and display. But when if my list has more than 10 records it needs to be paginated. . Since i follow a specific mvc , i could not provide any pagination logic there . Is there any way to achieve this . ...


"Learning is a Culture where your Eagerness & Curiosity plays a major Role".
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I can't use session since my handler class creates new session everytime .


Is this "new session everytime" a requirement or is it that you don't know how to prevent it?

Bill
manni ma
Greenhorn

Joined: Oct 07, 2011
Posts: 2
If I have understood your requirement clearly, one way is to have data holder class with arraylist as public static variable.
Populate this list with your data from servlet. This variable can be used from handler by using <Data Holder className>.<List name>.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

The session is the most appropriate means. If your sessions aren't behaving correctly, that needs to be addressed before anything else.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

BUT if you are holding more info in the array list than you are displaying, you are doing it wrong. If you are only going to display 10 records, only fetch the 10 records to be displayed. Fetching a bunch of records that might or might not end up being displayed is a sure case of premature optimization.
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

William Brogden wrote:
I can't use session since my handler class creates new session everytime .


Is this "new session everytime" a requirement or is it that you don't know how to prevent it?

Bill



I'm working on a product which is already developed and i need to develop a new module . The handler class is already defined in the product and i could not go change that. I should follow the existing MVC defined already. I have to impose my code on top of that. Please guide me ..
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

manni ma wrote:If I have understood your requirement clearly, one way is to have data holder class with arraylist as public static variable.
Populate this list with your data from servlet. This variable can be used from handler by using <Data Holder className>.<List name>.



I could have more than 1000 records for this . So i could not go for a static one since it will affect my performance at a very high..
 
 
subject: Passing ArrayList from JSP to Servlet
 
Similar Threads
Pagination in Struts2
pagination
Pagination
Pagination
Pagination issue