• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax Frameworks and servlets question

 
Joel Bushart
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet returning dynamically generated xml which I am requesting via AJAX using the prototype library.

However I'm having a slight issue with multiple requests to the servlet (which is expected as I'm feeding values from a database to update some fields in the html) and it is appending the xml to the previous request.

For example:
First request returns
<code>
<root>
<item1 price="12.30" name="tie" />
<item2 price="1.50" name="shoelace" />
</root>

Second request returns
<root>
<item1 price="12.30" name="tie" />
<item2 price="1.50" name="shoelace" />
<item1 price="12.30" name="tie" />
<item2 price="1.50" name="shoelace" />
<item3 price="14.99" name="shirt" />
</root>
</code>


I'm curious if any frameworks are designed to specifically return xml properly from jdbc calls via servlets or should I just roll my own solution?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, this is not to be expected and indicates that there is a coding error in your servlet if it is remembering previous values in subsequent calls.

I'm going to move this to the Servlets forum since it has little to do with Ajax, and everything to do with how you've coded your servlet.

Please supply your servlet code, and please use UBB code tags when posting it.
 
Joel Bushart
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In attempting to issolate the bug so I could post a consise sample, I discovered the problem to be an arraylist that I allocated on object creation, but not in the doGet(). I moved it into the doGet() method and all is well.

example:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly what I expected to see. Instance variables in servlets are death.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic