File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes attributes as objects in the context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "attributes as objects in the context" Watch "attributes as objects in the context" New topic
Author

attributes as objects in the context

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Hi,

I read as servlet container place attributes as objects in the context to use by servlets.

Also i read as servlets provde reference to file in javax.servlet.context.tempdir.

I would like to know more about what author meant. When attributes as objects user, where, benefits of using it. How to invoke it. Why it needs to be used along with context. Any ideas, suggestions, sample code, resources, links highly appreciated. Thanks in advance
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281

Since there is only one ServletContext exist for one web application it could be used as global respository to store global variable which could be used by different request or different session ,you just need to consider thread safety issue though because every request gets processed on there own thread b ut if you are just reading something from ServletContext you can safely do it.


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
Also i read as servlets provde reference to file in javax.servlet.context.tempdir.


There are some attributes that are supplied by webcontainer to the context.
All containers are responsible for creating a temporary directory. JSP .java and .class files and many things that get saved
in the tempdir(temporarily).

You can try : <%=application.getAttribute("javax.servlet.context.tempdir") %>
There are some attributes that are supplied to the context.The enumeration should not be empty
Edit1:to add last two lines
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: attributes as objects in the context