• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieve Value from Array to be Displayed

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my java codes. But i want to retrieve it from the array to be listed out in the jsp page. Could anyone guide me or give me a rough idea how to go about? Thanks


[ November 15, 2006: Message edited by: Eric Tan ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
if you retrieve your data in a servlet, simply put array as an attribute
of request before forwarding to JSP page.
I think, it would be better to use ArrayList class to store data, not Object[],
like this:



Then, using <c:forEach> JSTL tag, you can easily read item by item
and present it on the page:

or:


regards,
Natasza
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info. I will look into it and try it out.

If there is any additional info or website that could help me, please do post it up. Thanks alot
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some problem on the coding. I followed what you said on the previous post. I tried on my java page. whereby i put the codes in my page and tried it out. after i run it, it couldn't display any results from the file itself when i want to retrieve the results out.



this is part of the coding where the retrieve is. Maybe i am wrong in the codes that i put in. Can anyone guide me on this? Thanks
 
Natasza Biecek
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I posted the wrong reply at the wrong place. Sorry to disturb you again. But i still got some problem displaying my arraylist result in jsp
I posted my codes below, java and jsp page. hope that you could spare some time helping me again. really sorry about it. Thanks


i want to display the results of RetrieveData method in CountryMethod.java.
Thanks

RetrievePage.jsp
-----------------------------------------------------------------------




CountryMethod.java
---------------------------------------------------------------
 
Natasza Biecek
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sorry. I posted the wrong reply at the wrong place.
Sorry to disturb you again.


ok, there's no problem.

Eric, I assumed that you use servlet/jsp and bean, that was my fault...
Please, look at the code below - all set once again:

1) Country.java ( located in 'Test' package)


2) CountryMethod.java ( in 'Test' package, too )


3) RetrievePage.jsp


and let me put some remarks...

to pt.1
why population is stored as String? Don't you think that any numerical
type will be much better (for further calculations for example...)

to pt.2
in your original code (CountryMethod.java) the RetrieveData() method
does not return any data due to void at method signature...do you agree?
my implementation returns ArrayList, data is generated 'by hand',
so, please replace my code with yours to physically read data from db.
And of course add the rest of required stuff...

to pt.3
if you want to display this data, you have to create object
of CountryMethod class, then to call RetrieveData() method, right?
this method returns ArrayList object, so simply iterate through items
and print them out...

please, try to run my code 'as-is', then add whatever you need...

regards,
Natasza
[ November 18, 2006: Message edited by: Natasza Biecek ]
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Natasza. I will do that. If anything i am not sure of, i will post it up again. ;)
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did all the modification that is necessary. there is still abit error on the jsp page. maybe could you have a look. the error in jsp, i already bold it up. for the country.java, i didnt post it up because everything is just the same because it's just an accessor method to retrieve the value. didn't change anything on it...


Thanks alot for your help!


CountryMethod.java
--------------------------------------------------------





RetrievePage.jsp
-----------------------------------------------------------------
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Natasza
everything could work now.
Really appreciate it!



 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic