Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

how to pass values of array to jsp page.

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after populating the values to the array, return the array from the method you use in java class.

as simple as that.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, to set a scoped variable into the request for use on the JSP use request.setAttribute();
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic