• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

so close to having DB data put into bean, then into a table in a JSP

 
Greenhorn
Posts: 17
Netbeans IDE Windows Vista Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Title says it all....I need to place data from a DB into a java bean, and have the information displayed within a table in a jsp.
However I continue to get this error "javax.servlet.ServletException: java.lang.InstantiationException: bean courseBeanList not found within scope".
I am going to paste my code for servlet, jsp, bean, and beanList below. Any help would be greatly appreciated, and I do thank you in advance...
also this is my first post within this forum so be kind please .
JSP:


Servlet:
(there is more after this but doesnt have to do with this process.

Bean class:


beanList class:
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error occurs because you are visiting the page with the bean in it before it has been put into scope.
Is that a valid transition?

The difference is in your useBean statement. You have:


To get rid of the error message you can change it to:


The difference between using "class" and "type" is that with "class", if the bean doesn't already exist, it will instantiate it. Specifying type means that the bean should already be present, and it will throw an error if it is not.

As far as I can tell the bean is being instantiated and set into session in your servlet, so making sure you visit the servlet's url before you visit the JSP will also work around this issue, and may be the correct solution. It depends on your intended workflow.


Other feedback:
Rather than using scriptlet code in a JSP, it is suggested to use JSTL and EL.


Your Course bean seems a very thin wrapper around a List. I might almost suggest putting a list in scope rather than using a course bean.

In terms of Database code, it could be improved by using JNDI data source declared in your server, which would allow the server to do connection pooling, as opposed to opening a new database connection on each invocation of the servlet.
But what you have works :-)

 
Angel Kal
Greenhorn
Posts: 17
Netbeans IDE Windows Vista Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help, that did the trick
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic