• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Using JSP to Display a List of Numbers

 
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you got so far?
What part are you stuck on?
 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help with this List Issue:

My Servelt code:



My JSP code:

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give me an example of doing this with jstl?
 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found where I mis-spelled length but I am still getting the same Expected';' error.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey why are you using EL in a javascript?

Regards,
Srikkanth
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic