Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Angel Kal
Greenhorn
Posts: 17
Chrome Netbeans IDE Windows Vista
  • Mark post as helpful
  • send pies
  • 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:
 
Stefan Evans
Bartender
Pie
Posts: 1671
10
  • Mark post as helpful
  • send pies
  • 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
Chrome Netbeans IDE Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, that did the trick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic