File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Using JSP to Display a List of Numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using JSP to Display a List of Numbers" Watch "Using JSP to Display a List of Numbers" New topic
Author

Using JSP to Display a List of Numbers

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
A servlet runs a connection class to get a set of drawing numbers from an AS400 file. I want to display the result set in a pick list on a JSP so the user can get the detail info from a selected item in the list.

Thanks for the help.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What have you got so far?
What part are you stuck on?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
So far I have a java servlet that calls a class which makes a connection to the AS400 file and runs SQL statement bases on user input. I store the result set to an array using the rs.getArray(colName). Then the servlet opens the JSP which so far is blank. But I want to have a list on it of the array values which a user can select desired item and the details of that item will be displayed on another JSP.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
Please help with this List Issue:

My Servelt code:



My JSP code:

Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi,
you can save your data from the servlet setting it as a
application
session
request

attribute. In your servlet, you can write:
session.setAttribute("a_name_you_like", writeList);

Then, in your jsp page, you can refer it as ${sessionScope.writeList[0]},
${sessionScope.writeList[1]}, ...
However, I suggest you to use jstl.


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

This code connot resolve the writerList
Mirko has hit it on the head. We see nothing in your servlet that makes the value available to the JSP. The JSP cannot "see" local variables in your servlet.

Before you forward from the servlet to the JSP, create a scoped variable on the request with the data you want to send to the JSP (using request.setAttribute()).

Then use JSTL/EL on the page to access it. If you do not have the JSTL set up, now is the time. See the JSP FAQ for instructions.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
Can you give me an example of doing this with jstl?
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
I suppose I did not post enough of my servlet code:



I have the writerList scoped to a session attribute.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
Please help I am desprate.

Since I am setting the writerList as a session attribute why won't the following work in my JSP? If this will not work the rest of my code to fill in my drop down box will not work.



I keep getting an error about an Expected';'.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
I found where I mis-spelled length but I am still getting the same Expected';' error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

Since I am setting the writerList as a session attribute why won't the following work in my JSP?


Because you arte mixing JavaScript and Java. No can do. Perhaps this article might be helpful.

I suppose I did not post enough of my servlet code:


When are you planning to show us the whole servlet? Keeping us guessing as to how you are transitioning from the servlet to the JSP is not helping. A forward? A redirect?

In any case I don't know what a WriterList is. Does it implement List?
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Hey why are you using EL in a javascript?

Regards,
Srikkanth
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using JSP to Display a List of Numbers