I am having a method in my jsp which is supposed to return arraylist values like mentioned below.
EURUSD ,1.3231,1.3231, 8/9/2010 , 1:18pm
EURAUD ,1.4436,1.444, 8/9/2010 , 1:18pm
NZDAUD ,0.7954,0.7965, 8/9/2010 , 1:18pm .
When i try to print the returned values, the final value alone printed like
NZDAUD ,0.7954,0.7965, 8/9/2010 , 1:18pm
From java ranch forum's previous threads I read similar issue that,
[Post New]posted 19 March 2003 03:59
As I suspected, you only had 1 instance of object
that you keep re-set() your attribute. That's why you get the last data evertime.
What you might want to do is move the book info into separate object, let say Book which has the firstname, lastname, title, price, etc.
And your original object to contains a Collection
of Book, like ArrayList.
From an old thread.. My issue is similar as expalined above that I am able to print only final line of arraylist.. How can i print all lines. In jsp I am using only method not using any class. So how can I create object (like Book as above example). Can anyone help me out in this issue..
Thanks and Regards,
And I sincerely hope it's JSTL code and not Java in the JSP!
Otherwise, you are just going to create bad habits that will be hard to break out of later.
Rule #1 of modern JSP: no Java code in the JSP. At all. Ever.
Rather, your controller should perform any processing work that is required and send data (in the guise of scoped variables) to the JSP, which then uses the JSTL and EL to render the display.
You'd be best served to learn best practices right off the bat.
Thank you so much for your reply and valuable informations. And as you said, I revised my code for separation of logic and view. In that I have external method for executing my logic and that is returning a arraylist. For your reference code is given below,
And I am creating object for that class and calling the method from jsp as given below,
But how can I receive the returned arraylist in jsp. From my above code, is this right way to receive arraylist.. can you help me out in this issue..
I am attaching the error message for your reference..
type Exception report
description The server encountered an internal error () that prevented it from fulfilling this request.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 10 in the jsp file: /helloJSP.jsp
The method print(boolean) in the type JspWriter is not applicable for the arguments (void)
7: <body bgcolor="D2E9FF">
9: <% ForexTest forexObject = new ForexTest(); %>
10: "Forex Details : " <%= forexObject.getRate()%>
12: <%-- <% ForexTest forexObject = new ForexTest(); %>
13: <% forexObject.getRate(); %> --%>
Thanks and Regards,