Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to post UTF-8 values to a servlet

Reply
Thread Tools

how to post UTF-8 values to a servlet

 
 
Andy Fish
Guest
Posts: n/a
 
      12-20-2004
Hi,

I have a form with some text boxes, and I'm trying to post the data to a
servlet in utf-8 format (which I would have thought would be the default but
it appears not?)

the HTML file containing the form itself is definitely encoded in UTF-8, and
the form tag looks like this:

<form action="http://localhost:8080/foo/servlet" method="post" id="form1"
charset="UTF-8" name="form1">
<INPUT type="text" name="foo">
</form>

In the servlet I'm just calling request.getParameter("foo");

If I type in an English pound sign (this is the English currency symbol,
not #), I get £ (which is A circumflex followed by the pound sign).

I've been playing with various variations for 1/2 a day now and it's
starting to get me rather frustrated. Can anyone point me in the right
direction.

TIA

Andy


 
Reply With Quote
 
 
 
 
Collin VanDyck
Guest
Posts: n/a
 
      12-20-2004
> the HTML file containing the form itself is definitely encoded in UTF-8, and
> the form tag looks like this:
>
> <form action="http://localhost:8080/foo/servlet" method="post" id="form1"
> charset="UTF-8" name="form1">
> <INPUT type="text" name="foo">
> </form>
>
> In the servlet I'm just calling request.getParameter("foo");
>
> If I type in an English pound sign (this is the English currency symbol,
> not #), I get £ (which is A circumflex followed by the pound sign).
>
> I've been playing with various variations for 1/2 a day now and it's
> starting to get me rather frustrated. Can anyone point me in the right
> direction.
>



How are you testing for the value of getParameter("foo") ? If you are
outputting to the console and you are using Windows, you will very
likely get gibberish, as the Windows console does not output UNICODE
properly.

If this is true (console), then try outputting to a file instead and
open the text file with a UNICODE capable text editor.

Sorry if you've tried this already -- I beat my head into the wall for a
week before asking this same question on alt.text.xml and getting this
answer rather quickly.

Collin

 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      12-21-2004

"Collin VanDyck" <(E-Mail Removed)> wrote in message
news:ZNGxd.5038469$(E-Mail Removed)...
>> the HTML file containing the form itself is definitely encoded in UTF-8,
>> and the form tag looks like this:
>>
>> <form action="http://localhost:8080/foo/servlet" method="post" id="form1"
>> charset="UTF-8" name="form1">
>> <INPUT type="text" name="foo">
>> </form>
>>
>> In the servlet I'm just calling request.getParameter("foo");
>>
>> If I type in an English pound sign (this is the English currency
>> symbol, not #), I get £ (which is A circumflex followed by the pound
>> sign).
>>
>> I've been playing with various variations for 1/2 a day now and it's
>> starting to get me rather frustrated. Can anyone point me in the right
>> direction.
>>

>
>
> How are you testing for the value of getParameter("foo") ? If you are
> outputting to the console and you are using Windows, you will very likely
> get gibberish, as the Windows console does not output UNICODE properly.
>
> If this is true (console), then try outputting to a file instead and open
> the text file with a UNICODE capable text editor.
>


No, I'm looking at it in the debugger. I can see that the string is of
length 2 characters.

Andy

> Sorry if you've tried this already -- I beat my head into the wall for a
> week before asking this same question on alt.text.xml and getting this
> answer rather quickly.
>
> Collin
>



 
Reply With Quote
 
Andy Fish
Guest
Posts: n/a
 
      12-21-2004

"Andy Fish" <(E-Mail Removed)> wrote in message
news:y2Fxd.3780$(E-Mail Removed) k...
> Hi,
>
> I have a form with some text boxes, and I'm trying to post the data to a
> servlet in utf-8 format (which I would have thought would be the default
> but it appears not?)
>
> the HTML file containing the form itself is definitely encoded in UTF-8,
> and the form tag looks like this:
>
> <form action="http://localhost:8080/foo/servlet" method="post" id="form1"
> charset="UTF-8" name="form1">
> <INPUT type="text" name="foo">
> </form>
>
> In the servlet I'm just calling request.getParameter("foo");
>
> If I type in an English pound sign (this is the English currency symbol,
> not #), I get £ (which is A circumflex followed by the pound sign).
>
> I've been playing with various variations for 1/2 a day now and it's
> starting to get me rather frustrated. Can anyone point me in the right
> direction.
>


FWIW, my solution was to call request.setCharacterEncoding("UTF-8") at the
top of the doPost method.

I'm not entirely happy with hard-coding it this way, but hey it seems to
work.


> TIA
>
> Andy
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Offending class: javax/servlet/Servlet.class chamikara Java 1 06-19-2004 05:42 AM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Tomcat: POST from one servlet or internal class to another servlet Sean Clarke Java 1 01-07-2004 02:22 PM
how to get my servlet configuration before the servlet is initialised Andy Fish Java 4 12-17-2003 09:47 PM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM



Advertisments