Hi- I have some objects that will be used frequently throughout my app. I want to add them as servlet context attributes when the web app starts. What is the best way to do this? I guess I could create a servlet that never gets called via a url, add the attributes on the init() method,and specify load-on-startup in web.xml. This seems kind of sloppy. Is there a better way?
In years past, Servlet and JSP developers were always running into just this very problem. The solution typically was to code everything into a Servlet that loads at startup, but as you say, that is sloppy.
Similarly, the other problem that existed was "how do you make sure a user has something inside the session as soon as it is created." To address this question, they now provide a session listener.
When you code this listener, don't forget to update the deployment descriptor. A Java file alone won't be recognized by the web container. I put together an online tutorial for coding a listener, just in case you're interested: