I have a Form which is displayed in UTF-8. The form 
contains just one editable field, namely 
<textarea name="test"></textarea>. 

   When I submit this to a JSP:
   ----------------------------
   I can extract the value of the string using,
   <%
   String s = request.getParameter("test");
   %>

   I then write the value of s to a UTF-8 file with this
   <% 
   PrintWriter o = new PrintWriter(new OutputStreamWriter(new 
FileOutputStream("output.html"), "UTF-8"));
   o.write(msg);
   o.flush();
   o.close();
   %>

Opening the file "output.html" with a browser, I 
see that the original UTF-8 text is still perfectly 
intact and encoded as recognizable UTF-8.  
Hooray, it works.

   
But when I submit the form to a servlet
-----=---------------------------------
If I submit the form to a servlet, and try the same code,

   String s = request.getParameter("test");
   PrintWriter o = new PrintWriter(new OutputStreamWriter(new  
FileOutputStream("output.html"), "UTF-8"));
   o.write(msg);
   o.flush();
   o.close();
   
Then the text is no longer recognizable. 
Same if I try to output 's' to the browser (after 
setting ContentTYpe to text/html;charset=uTF-8)
   
It WILL however work if I do the following:   

   String s = new String(request.getParameter("test").getBytes("8859_1"), "UTF-8");

This is screwing with my head. 
First off, I thought that all JSP become servlets 
anyway so there should be no discrepancy between the first
and second sets of code. 

Secondly, Tomcat seems pretty inconsistent
in that "s=request.getParameter()" works in a JSP but 
not in a servlet.

Has anybody else noticed this ? 
Or can anybody account for this behaviour ? 

Thank you,

Stephen.





---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

Reply via email to