Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JSP to Display a List of Numbers

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you got so far?
What part are you stuck on?
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help with this List Issue:

My Servelt code:



My JSP code:

 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give me an example of doing this with jstl?
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose I did not post enough of my servlet code:



I have the writerList scoped to a session attribute.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found where I mis-spelled length but I am still getting the same Expected';' error.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey why are you using EL in a javascript?

Regards,
Srikkanth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic