Originally posted by Mala Sharma:
Hello Ben,
First of all, thanks alot for providing me that code. I just want to see if i understood it right. Lets say i make a class to which i pass all the attribute to be set for the entire application. Would it be something like this:
would that be Sufficient? THanks for clarifing this. I really appreciate it.
Mala
You forgot the empty parenthesis after getServletContext.
It should have been getServletContext
().setAttribute(....
Also, setAttribute doesn't trow any exceptions so the throws clause is unecessary unless you plan on adding code that does.
Non-servlet classes aren't going to have a getServletContext() method so you would need to pass the servlet context to that class somehow. As a rule I try to make all of my beans 'servlet unaware'. If you have a bean that requires a servletContext object in order to run, you won't be able to
test it outside of the container.