• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Context setAttribute getAttribute

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic