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 .
(there is more after this but doesnt have to do with this process.
Joined: Jul 06, 2005
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.
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 :-)