Google Answers Logo
View Question
 
Q: Tomcat UTF-8 Problem with request.getParameter() ( No Answer,   2 Comments )
Question  
Subject: Tomcat UTF-8 Problem with request.getParameter()
Category: Computers
Asked by: noodlestudio-ga
List Price: $20.00
Posted: 14 Oct 2005 19:15 PDT
Expires: 13 Nov 2005 18:15 PST
Question ID: 580467
I have a web application that support UTF-8 and has been working fine
when I was using OC4J as the servlet/jsp container.  I have several
forms that allow user to submit UTF-8 characters. The JSP will use
request.getParameter() to display the UTF-8 characters into the
browser.

However, after I migrated to Tomcat 5.0, and the JSP pages are having
problems in handling UTF-8 characters. After trying several attempts,I
discover that having "<%@page contentType="text/html;charset=UTF-8"%>"
on my JSP pages is the main caused that makes the
request.getParameter() not handling the UTF-8 properly. If I removed
it, then it works just fine.

How can I make things work both for Tomcat 5.0 and OC4J without
removing the "<%@page contentType="text/html;charset=UTF-8"%>" line?


The following is my setup:
- Tomcat 5.0
- JDK 1.4.2_05
- Windows XP

Tomcat's server.xml
    <Connector port="8080"
               URIEncoding="UTF-8"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               disableUploadTimeout="true" />

Note: I do not want to add any java code changes programatically by
creating a new String that convert values into UTF-8.
Thanks for your help in advance.

Clarification of Question by noodlestudio-ga on 16 Oct 2005 23:31 PDT
currently the server.xml is located in the same server as the web application.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Tomcat UTF-8 Problem with request.getParameter()
From: webkid-ga on 15 Oct 2005 01:53 PDT
 
i've had the exact same problem before actually; oddly enough it
worked when the xml file was on the same server as the application.
how is that in your case? unfortunately i have no real answer for the
problem if you do not want to alter the java code/xml parser.
Subject: Re: Tomcat UTF-8 Problem with request.getParameter()
From: warmpark-ga on 29 Oct 2005 10:20 PDT
 
First. Edit Tomcat's server.xml (add URIEncoding="UTF-8" in Connector tag)
       You're already good
    <Connector port="8080"
               URIEncoding="UTF-8"
               ... />

Second. In the Catalina.bat (windows) file there must be a switch
added to the call to java.exe. The switch is: -Dfile.encoding=UTF-8

Here is example >> you can't miss where you add [-Dfile.encoding=UTF-8]
Good luck to you !! 

rem Execute Java with the applicable properties
if not "%JPDA%" == "" goto doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS%
-Dfile.encoding=UTF-8 -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%"
-classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%"
-Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%"
%MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS%
-Dfile.encoding=UTF-8 -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%"
-classpath "%CLASSPATH%" -Djava.security.manager
-Djava.security.policy=="%SECURITY_POLICY_FILE%"
-Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%"
-Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS%
%ACTION%
goto end
:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% -Xdebug
-Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n
%DEBUG_OPTS% -Dfile.encoding=UTF-8
-Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%"
-Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%"
-Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS%
%ACTION%
goto end
:doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS%
-Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n
%DEBUG_OPTS% -Dfile.encoding=UTF-8
-Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%"
-Djava.security.manager
-Djava.security.policy=="%SECURITY_POLICY_FILE%"
-Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%"
-Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS%
%ACTION%
goto end

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy