I am developing a struts application, and I want to have my database credentials configured. So I had put it in my web.xml under <context-param>. I have a listener class which reads these parameters and sets it to the ServletContext.
I have another java class which will get the backend datbaase connection, here If I use "getServletContext().getAttribute("dbName");" I get an error "method getServletContext() is undefined for my class"
can anyone let me know how can I get the set ServletContext attributes in my "DbConnection" java files.
The getServletContext() method belongs to the GenericServlet so unless you extend GenericServlet or HttpServlet you will not be able to use the method directly.
You could also get the servletContext using sessions - I think its session.getServletContext().
Of course your DBA class is unlikely to have access to either; so you would have pass the Connection String to the DBA class somehow - I not really sure of a good way in which this could be done. (I would generally end up using a CONSTANT to hold the database connection String).
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.