wood burning stoves 2.0*
The moose likes JSP and the fly likes Retrieve Value from Array to be Displayed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Retrieve Value from Array to be Displayed" Watch "Retrieve Value from Array to be Displayed" New topic
Author

Retrieve Value from Array to be Displayed

Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
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 ]
Natasza Biecek
Greenhorn

Joined: Oct 26, 2006
Posts: 28
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

Joined: Oct 11, 2006
Posts: 72
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

Joined: Oct 11, 2006
Posts: 72
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

Joined: Oct 26, 2006
Posts: 28
Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
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

Joined: Oct 26, 2006
Posts: 28
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

Joined: Oct 11, 2006
Posts: 72
Thanks Natasza. I will do that. If anything i am not sure of, i will post it up again. ;)
Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
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

Joined: Oct 11, 2006
Posts: 72
Thanks Natasza
everything could work now.
Really appreciate it!



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieve Value from Array to be Displayed
 
Similar Threads
Calling the Java Store Method in JSP
Necessary to initialize bean properties?
My Small Web Project - but has some problems - please help ...
Calling Java Method
how to get the text box value