Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Context setAttribute getAttribute

 
Stu Higgs
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stu Higgs
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic