aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax - problem with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax - problem with "%" in xhtml payload - Java error" Watch "Ajax - problem with "%" in xhtml payload - Java error" New topic
Author

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

marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

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

when in doubt put it in parenthesis and stick a dollar sign in front of it, only good can come from this.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

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

Joined: Jan 10, 2002
Posts: 61434
    
  67

Have you properly URL-encoded the string?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you submitting via GET or POST?
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

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

Joined: Jan 10, 2002
Posts: 61434
    
  67

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

Joined: Feb 03, 2007
Posts: 178

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

Joined: Feb 03, 2007
Posts: 178

Answered my own question

client side


and on the server side


and it's all there, beautiful!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 03, 2007
Posts: 178

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

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax - problem with "%" in xhtml payload - Java error