• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax - problem with "%" in xhtml payload - Java error

 
marten kay
Ranch Hand
Posts: 184
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sending back style properties and their values from the client to the server in an xml document contained in a javascript String object. This is all working fine except when the String object (contained in the Xhtml payload) includes the following property/string

When the above property is included in the String object I get a runtime error in my receiving servlet at the line

The error being reported is
28/06/2009 12:18:24 org.apache.tomcat.util.http.Parameters processParameters
WARNING: Parameters: Character decoding failed. Parameter skipped.
java.io.CharConversionException: isHexDigit

The process work well with all other properties (even with Hex color values), so I am suspecting it is something with the percentage % sign in the String in the payload.

Would anybody be able to provide me with a clue on what the problem maybe, and where I need to look to find a solution?

Thanks

Marten
 
marten kay
Ranch Hand
Posts: 184
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have worked around the problem - no longer sending back the percentage sign.

I May revisit this issue when my new Ajax book arrives.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you properly URL-encoded the string?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you submitting via GET or POST?
 
marten kay
Ranch Hand
Posts: 184
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

I'm not sure if I have URL-encoded the string properly, and I am using a POST.

My Ajax code that sends payload is below.



createXml() returns a string.

I suspect that Ajax is not simple at it first looks here, and that I will need to read a more advanced book to get this right.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not Ajax that's tripping you up, but your misuse of HTTP.

You say that the POST is of type "application/x-www-form-urlencoded", then pass XML rather than form encoding. And then you expect getParameter to be able to do something with the XML? Of course, it's going to foul up.

You need to properly format and encode the POST body.
 
marten kay
Ranch Hand
Posts: 184
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great, this XMLHttp thing is making more sense now - but I am now not able to access the payload on the server.

I set the header as

but how do I set up the payload on the client? and how do I get access to the payload from request object on the server?
I have tried googling, looking through my inadequate books and playing around with xhtmlPayload= "Payload=" + createXml() on the client with request.getParameter("Payload") on the server without luck, or do I use the request.getInputStream().

any further clues appreciated


 
marten kay
Ranch Hand
Posts: 184
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answered my own question

client side


and on the server side


and it's all there, beautiful!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of curiosity, why do that by hand instead of using something like Prototype or jQuery? I mean, it's good to know what's happening underneath and all, but still.
 
marten kay
Ranch Hand
Posts: 184
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by way of explanation

I am not coming to this as a programmer but from an idea that I am trying to work through, so I am learning coding as I go along. I have used two frameworks in my journey, Struts for server-side and Dojo for the client-side, and I ended up finding both restrictive. So my experience has been that learning frameworks takes up learning time, and tends to lead to dead ends. So I am avoiding them for now.

While I now find JQuery interesting, I have basically completed my client-side stuff, and am now moving back to doing the Java stuff on the server side.

Perhaps I can use frameworks when I refactor later when my idea is settled and I can afford to employ people to refactor my code. But until then...

Well, that's my story for now anyway
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frameworks also allow you to focus on the actual purpose of your application rather than low-level trivialities (*especially* when it comes to Ajax/JavaScript and browser compatibility issues). YMMV.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic