aspose file tools*
The moose likes XML and Related Technologies and the fly likes Problem with SAXParser when using with servlets. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem with SAXParser when using with servlets." Watch "Problem with SAXParser when using with servlets." New topic
Author

Problem with SAXParser when using with servlets.

Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
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.
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
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

Joined: May 19, 2004
Posts: 37
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

Joined: Sep 25, 2003
Posts: 327
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

Joined: May 19, 2004
Posts: 37
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: May 19, 2004
Posts: 37
Hai

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

pooja.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with SAXParser when using with servlets.