You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by red phoenix <ro...@gmail.com> on 2007/05/08 17:23:53 UTC

Tomcat6.0.10 Character Code question

I have set my all files with UTF-8 format,so I set URIEncoding parameter in
server.xml,like follows:
<Connector port="8080" protocol="HTTP/1.1"
               maxThreads="150" connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>
Then I write a JSP file like follows:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:form method="post" action="test.do">
<s:textfield label="Name" name="Name"/>
<s:submit name="do"/>
</s:form>

In test.do action,I get the value of Name from JSP,like follows:
request.getParameter("Name");
System.out.println("Name="+Name);
If I input english name in the field Name in JSP,when I submit,the
test.dowill receive right english name,but when I input chinese name
in the field
Name in JSP,test.do will receive not right name,it will show ???[B@15b1773
I know it must be wrong in character change.But I don't want to change
URIEncoding from UTF-8 to GB2312 in the server.xml file,I guess I should do
something in test.do,but I don't know how to do it.
Anybody could tell me how to do it? Would you give me some code?

Thanks

Re: Tomcat6.0.10 Character Code question

Posted by Mark Thomas <ma...@apache.org>.
red phoenix wrote:
> Anybody could tell me how to do it? Would you give me some code?

The following index.jsp works for me:
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
     <title>Character encoding test page</title>
   </head>
   <body>
     <p>Data posted to this form was:
     <%
       request.setCharacterEncoding("UTF-8");
       out.print(request.getParameter("mydata"));
     %>

     </p>
     <form method="post" action="index.jsp">
       <input type="text" name="mydata">
       <input type="submit" value="Submit" />
       <input type="reset" value="Reset" />
     </form>
   </body>
</html>

Mark

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org