aspose file tools*
The moose likes Servlets and the fly likes Servlet Context setAttribute getAttribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Context setAttribute getAttribute" Watch "Servlet Context setAttribute getAttribute" New topic
Author

Servlet Context setAttribute getAttribute

Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
I'm trying to return a DOM and store it in the ServletContext via

sc.setAttribute("myDom", new TDOMBuilder(sXmlFilePath));

no problem so far, but I am not sure whether this is even allowed or not?

Then, I am trying to send that DOM stored in myDom to a method that will use the DOM in an XSLT transform like this:

new TXMLTransformer(sXSLFilePath, sc.getAttribute("myDom"))

My question is how do I get the constructor in TXMLTransformer to see sc.getAttribute("myDom") as a Document type without a ClassCastException?

I have tried to set the constructor arg to Document, but then compiler complains that TXMLTransformer is looking for an Object type arg not supplied. If changing to Object in the TXMLTransformer arg, then later in TXMLTransformer how do I get that object to be of Document Type without ClassCastException?

Thanks.

EDIT:

I believe I have solved the problem by using this:

sc.setAttribute("myDom", new TDOMBuilder(sXmlFilePath).document);

prior to that I think I was just returning the Object and not the reference to the member variable in the object.

Now I am wondering if I will be able to access myDom via sc.getAttribute("myDom") from any servlet, and is it now stored similarto a session object?

Thanks.
[ January 30, 2006: Message edited by: Stu Higgs ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The get and setAttribute methods of ServletContext work the same way they do for the session or request scopes (except for their scope, of course).
You're just binding an object to a map and then retrieving it with a key.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Context setAttribute getAttribute
 
Similar Threads
Single User Problem
Writing a File and Request Dispatcher Forward
trouble passing info from servlet to jsp
Which is best way to go for optimal memory use?
Get member variable value from Servlet Context Object