This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to pass values of array to jsp page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to pass values of array to jsp page." Watch "how to pass values of array to jsp page." New topic
Author

how to pass values of array to jsp page.

Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
Hello,

I am having one java class, in that i am having some arrays & i want to pass these array
elements to jsp page for displaying purpose. How should i do this.

My project's flow is like this--> jsp page..servlet..java class(here i am having array).. now i want jsp page for displaying contents of array.
Bennet Xavier
Ranch Hand

Joined: Jun 19, 2008
Posts: 162
Hi ,

String arr[ ];
request.setParameter("InvalidMeetingDates", arr);

do this in servlet and get the attribute in jsp for iterating by

String[] str = (String[])request.getAttribute("InvalidMeetingDates");

thanks and regards,
Bennet
Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
Bennet Xavier wrote:Hi ,

String arr[ ];
request.setParameter("InvalidMeetingDates", arr);

do this in servlet and get the attribute in jsp for iterating by

String[] str = (String[])request.getAttribute("InvalidMeetingDates");

thanks and regards,
Bennet



Hi,
Thanks for your reply,
Mean now i can pass the array elements from servlet to jsp,
but actually i am using java class, in it i am having array.
Now again the question will arise that how i will pass this array from java class to servlet.
If this problem will be solved then my whole problem will get solved.
Please reply.
Thank you once again...
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Rupa Katkar wrote:Now again the question will arise that how i will pass this array from java class to servlet.

Servlet is like any other Java class. So how can you return an array of instance or local variable from a method ? Isn't that a basic question of general programming ?
Bennet Xavier
Ranch Hand

Joined: Jun 19, 2008
Posts: 162
after populating the values to the array, return the array from the method you use in java class.

as simple as that.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Bennet Xavier wrote:request.setParameter("InvalidMeetingDates", arr);

There is no such methiod.

do this in servlet and get the attribute in jsp for iterating by
String[] str = (String[])request.getAttribute("InvalidMeetingDates");

That assumes the use of scriptlets which should not longer be sued in JSPs.

Use the JSTL and El instead.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

By the way, to set a scoped variable into the request for use on the JSP use request.setAttribute();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to pass values of array to jsp page.