Meaningless Drivel is fun!*
The moose likes JSP and the fly likes so close to having DB data put into bean, then into a table in a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "so close to having DB data put into bean, then into a table in a JSP" Watch "so close to having DB data put into bean, then into a table in a JSP" New topic
Author

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

Angel Kal
Greenhorn

Joined: Dec 11, 2011
Posts: 17

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

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Dec 11, 2011
Posts: 17

Thanks for your help, that did the trick
 
 
subject: so close to having DB data put into bean, then into a table in a JSP
 
Similar Threads
Problem displaying report using JSP
Select clause for listing cities for refined search
Forms in servlet
trouble with remove item fro shopping cart
iterate problem in struts2