Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning arrayList and Final line value alone getting printed in jsp  RSS feed

 
Ramesh Jambulingam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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,
Ramesh.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might help, don't you agree, to show the code in question?

And I sincerely hope it's JSTL code and not Java in the JSP!
 
Ramesh Jambulingam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I am attaching my jsp code,




and I am sorry for java inside jsp because I am new jsp itself. step by step I wil learn jstl also and wil post queries..


Thanks and Regards,
Ramesh.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are new to JSP, then it imperative that you learn how to do things the right way now!

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.
 
Ramesh Jambulingam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

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

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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">
8:
9: <% ForexTest forexObject = new ForexTest(); %>
10: "Forex Details : " <%= forexObject.getRate()%>
11:
12: <%-- <% ForexTest forexObject = new ForexTest(); %>
13: <% forexObject.getRate(); %> --%>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)



Thanks and Regards,
Ramesh.
 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

you are adding the reference of string to the arraylist
as you iterate string reference(tmpString2) will point to next line
and at last it will point to last entry
please correct it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!