dcsimg
saving and retrieving from the ServletContext
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chris_matthews
Posted On:   Sunday, September 15, 2002 01:15 AM

I have a simple web app that does some database queries and presents the data. I am using MVC pattern with a controllerservlet and beans and jsp's I create the connection in the init() method and I want to save it to the ServletContext so that my beans can access the connection - it is the beans that do the queries. The difficulty I am facing is the the getServletContext().setAttribute("connection",conn) doesn't seem to work as when I use getServletContext.getAttribute(conn) in my beans I get a null pointer exception. I know the init() method does get a connection by viewing the logs, and my beans work correctly. It is just    More>>

I have a simple web app that does some database queries and presents the data.

I am using MVC pattern with a controllerservlet and beans and jsp's

I create the connection in the init() method and I want to save it

to the ServletContext so that my beans can access the connection - it is

the beans that do the queries.


The difficulty I am facing is the the getServletContext().setAttribute("connection",conn)

doesn't seem to work as when I use getServletContext.getAttribute(conn)

in my beans I get a null pointer exception. I know the init() method does get a

connection by viewing the logs, and my beans work correctly. It is just putting it all

together that doesn't seem to work.

This is a simple one person at a time type app for work so there

is no need for connection pooling.

Am I using the right methods for saving objects in the ServletContext ???


thanks in advance,
Chris

   <<Less

Re: saving and retrieving from the ServletContext

Posted By:   Eelco_Cramer  
Posted On:   Tuesday, September 17, 2002 02:23 AM

you should use getServletContext.getAttribute("connection") to retrieve the object you saved to the servlet context with the key value 'connection'. The return value of getServletContext.getAttribute("connection") will be your connection object, you should cast it to the proper object type before you can use it.
About | Sitemap | Contact