aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Encoding and problems with 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 » HTML, CSS and JavaScript
Bookmark "Encoding and problems with" Watch "Encoding and problems with" New topic
Author

Encoding and problems with

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
Hey all,
I have an application that needs to store equations in a form as hidden fields. One such example, would be a multiplication equation whereby 8 x b = 16. Instead of using a "x" for the muliplication I use the html code for it. Upon clicking a button the string is to be passed to a javascript, along with some other values) are to be passed (using an AJAX call) back to the server. When the call is made (to a perl script on the server) the content is then written to a file on the server. Where the multiplication symbol text is to be, there are "weird" symbols in their places. If I put an alert in the javascript (whereby the value is retrieved from the form) the html code shows a round dot and not the actual text representing the dot. My question is: how can I grab such values from the form and send them to the server as the text representing the symbols? Would greatly appreciate a response.

Rob
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
Correction on second code entry - should be a & before the bull and not $.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823


strOut has name-value pairings separated by "&"s. One of the name-value pairings is one whereby the value has a & bull; tag within it. When received on the server the value is stored as an encoded value. If I use :


the & bull; tags and everything else go across fine and is stored correctly. The reason I switched from GET to POST was because of size limitations. Using POST I am able to send the data I want across without hitting the limit I hit before.
Can anyone answer how I can still use POST but still have the data go as though using GET? Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Rob Hunter wrote:Can anyone answer how I can still use POST but still have the data go as though using GET?

I have no idea what you mean by that.

Do you mean passing the data on the query string? I'd guess not, as the limitations of that is why you switched to post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
If you store & bull; (without the space) in a hidden field and then in javascript try to use an AJAX call to a srcipt on the server (i.e. Perl) the value is retrieved and stored in file fine when using "GET" at the method (tacking on the name-value pairings onto the URL). If you use "POST" method and put the string in as an argument to ajaxObj.send() then the & bull; is stored as this "•". The reason I gave up using GET is because of string length limitation but I've encountered this issue with POST now. Should I set my header type to something to "mime"ic that of GET? Is there somethign else I should do? Thanks for the response Bear.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
Easier test/way to look at it:
(1) store & bull; in a cookie and put the value of the cookie in an alert. It pops up with & bull; in the popup.
(2) store & bull; in a hidden field. In an alert put the value of the hidden field. It pops up displaying an actual bullet.
How can I grab the actual text that was inserted into a hidden field or revert back to the text and not have the symbol represented in the text?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

But that's just an example of how two specific things work in your browser. It doesn't tell us what you want done.

My belief is that data in fields is sent as-is when the browser submits the form. The values will be URL-encoded when they are GET parameters, of course, but your servlet container will URL-decode them before giving them to you. Which results in as-is, anyway.

From your post I can't tell what you think your problem is, or what you are using to diagnose it. You should be aware that (as in the two examples you showed) that the tools you're using to "observe" a problem may in fact be creating a supposed problem by interpreting the data in an undesired fashion.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

You need to encode the parameter values. See encodeURIComponent.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Or take the guesswork out of it all and use jQuery to do your Ajax.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
Hey Bear,
Thanks for the response but it doesn't seem to work. Try taking a hidden field and putting a & bull; into it and then have an alert in javascript to print the value of that field. It doesn't display & bull; as text but rather the dot. If stored in a cookie and shown in an alert it shows & bull; (as text). If I set the method as GET for the AJAX call it passes everything to the server fine, if POST it send back crap (characters I posted previously).

Rob
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Code?
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
All you have to do to see it can be shown below. If you run and the alert comes up you see a dot (bullet). If I had a cookie set and retrieved the value in the alert you would see "•". If I ran an Ajax call using GET and passed in document.getElementById("bullValue"), as below, the value would be retrieved fine on the server side. Using POST method for the AJAX call it messes it up by the time it gets to the server. GET is obviously doing something that POST isn't to the data being passed. I posted the character string that gets to the server and saved above.

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
Even in the value field it shows a dot, what I put in there was $# 149 ; (remove spaces).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encoding and problems with