• 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

Problem with SAXParser when using with servlets.

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai All,

Problem with SAXParser when using with servlets.
I am finding problem in retrieving the values from enddocument method of DocumentHandler from my dopost method of servlet. But am able to retrieve the values from other method.

i am having a global variable sid which will be assigned some value in enddocument method of DocumentHandler, which i need to use in doPost method. But when i try to do so its giving the value 0, instead of original value.

The sample code which i am using is as follows.
-----------------------------------------------



Can any one let me know how to get the value assigned in the end

document method.

Any help would be appreciated.
Thanks in advance
pooja.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First and foremost, all class names should begin with a capital letter.

Second, org.xml.sax.helpers.DefaultHandler is a class, not an interface. Hence, you must extend it rather than implementing it.

Your "result" variable is being set properly because you are calling the changethevalue() method explicitly. The "sid" variable is not being set because the endDocument() method is not being called.
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai

Thanks for ur quick reply.
I am sorry that in my previous post i have mentioned it as DefaultHandler, actually i have implemented ContentHandler.

As this is a test program i have not given much attention to class names.
Is there any way to get the value assigned in the enddocument method.
As this method is called when the parser.parser() method is called.
And its even printing that its inside the enddocument method.

Plz let me know if there is a way to get the value.
Thanks for all ur suggestions.
I appreciate ur help
Pooja
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its hard to tell what is actually happening since it is clear that the code you are running is not what you have in your first post.
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the exact code which i am using.
I have copied and pasted it.


My problem is that i have to send some value in servlet response which is produced in enddocument method. I have tried a lot byt failed to do so.
I value is printing fine in enddocument method. But from doPost method the variable is not holding its value. Is it some thing like scope of variable is limited only to these event handler methods.

thanks for ur reply
pooja
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I strongly suggest you write a separate class implementing ContentHandler rather than mix servlet and SAX methods in the same class. There are several advantages:
1. You can test it outside the servlet environment - always a plus
2. You won't have to worry about instance variables in the servlet being shared by all request Threads.
3. Testing will be a lot faster without having to stop and start the servlet engine.
Bill
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai

Thank you !!!
Thanks a lot for ur reply.
I appreciate ur help.

pooja.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic