This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi all! I'm using jsp,servlets,tomcat 4 to develop a webapplication. The application can be accessed in many languages. I used to develop my applications in asp , com before and there I could make an application object i global.asa load text from the database into the object and use it to gain text from the object. If let's say the user clicked the US flag then english text could be retrieved from the object. I used this so that I wouldn't have to access the database for every word printed on the page. My question is. How do I do this in java.
I'm now using classes from Collection package and populates the collection from the database. Now how can I store the my class in memory so that I can get data from my class not using new. i don't want to get the data from the database, just from the object! // Mathias
You can use the ServleteContext. In your servlet do ServletConext sc = getServletContext(); then you cam store object references in the ServletContext like this MyDataObject mdo = new MyDataObject(); sc.setAttribute("foo", mdo); then to retrieve the data MyDataObject mdo2 = (MyDataObject)sc.getAttribute("foo");
Kevin Jones<br />Author: <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0321136497/jranch-20" target="_blank" rel="nofollow">Servlets and JSP: The J2EE Web Tier</a>
Joined: Oct 13, 2003
Thanks! My english is a little weak. "ServletContext" what does that mean exactly? // Mathias