Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3501212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:49:51+00:00 2026-05-18T12:49:51+00:00

I have a tomcat based application that needs to submit a form capable of

  • 0

I have a tomcat based application that needs to submit a form capable of handling utf-8 characters. When submitted via ajax, the data is returned correctly from getParameter() in utf-8. When submitting via form post, the data is returned from getParameter() in iso-8859-1.

I used fiddler, and have determined the only difference in the requests, is that charset=utf-8 is appended to the end of the Content-Type header in the ajax call (as expected, since I send the content type explicitly).

ContentType from ajax:
“application/x-www-form-urlencoded; charset=utf-8”

ContentType from form:
“application/x-www-form-urlencoded”

I have the following settings:

ajax post (outputs chars correctly):

$.ajax( {
  type : "POST",
  url : "blah",
  async : false,
  contentType: "application/x-www-form-urlencoded; charset=utf-8",
  data  : data,
  success : function(data) { 
  }
 });

form post (outputs chars in iso)

 <form id="leadform" enctype="application/x-www-form-urlencoded; charset=utf-8" method="post" accept-charset="utf-8" action="{//app/path}">

xml declaration:

<?xml version="1.0" encoding="utf-8"?>

Doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

meta tag:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

jvm parameters:

-Dfile.encoding=UTF-8

I have also tried using request.setCharacterEncoding(“UTF-8”); but it seems as if tomcat simply ignores it. I am not using the RequestDumper valve.

From what I’ve read, POST data encoding is mostly dependent on the page encoding where the form is. As far as I can tell, my page is correctly encoded in utf-8.

The sample JSP from this page works correctly. It simply uses setCharacterEncoding(“UTF-8”); and echos the data you post. http://wiki.apache.org/tomcat/FAQ/CharacterEncoding

So to summarize, the post request does not send the charset as being utf-8, despite the page being in utf-8, the form parameters specifying utf-8, the xml declaration or anything else. I have spent the better part of three days on this and am running out of ideas. Can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:49:52+00:00Added an answer on May 18, 2026 at 12:49 pm

    form post (outputs chars in iso)

    <form id="leadform" enctype="application/x-www-form-urlencoded; charset=utf-8" method="post" accept-charset="utf-8" action="{//app/path}">
    

    You don’t need to specify the charset there. The browser will use the charset which is specified in HTTP
    response header.

    Just

    <form id="leadform" method="post" action="{//app/path}">
    

    is enough.


    xml declaration:

    <?xml version="1.0" encoding="utf-8"?>
    

    Irrelevant. It’s only relevant for XML parsers. Webbrowsers doesn’t parse text/html as XML. This is only relevant for the server side (if you’re using a XML based view technology like Facelets or JSPX, on plain JSP this is superfluous).


    Doctype:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    

    Irrelevant. It’s only relevant for HTML parsers. Besides, it doesn’t specify any charset. Instead, the one in the HTTP response header will be used. If you aren’t using a XML based view technology like Facelets or JSPX, this can be as good <!DOCTYPE html>.


    meta tag:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    

    Irrelevant. It’s only relevant when the HTML page is been viewed from local disk or is to be parsed locally. Instead, the one in the HTTP response header will be used.


    jvm parameters:

    -Dfile.encoding=UTF-8
    

    Irrelevant. It’s only relevant to Sun/Oracle(!) JVM to parse the source files.


    I have also tried using request.setCharacterEncoding("UTF-8"); but it seems as if tomcat simply ignores it. I am not using the RequestDumper valve.

    This will only work when the request body is not been parsed yet (i.e. you haven’t called getParameter() and so on beforehand). You need to call this as early as possible. A Filter is a perfect place for this. Otherwise it will be ignored.


    From what I’ve read, POST data encoding is mostly dependent on the page encoding where the form is. As far as I can tell, my page is correctly encoded in utf-8.

    It’s dependent on the HTTP response header.

    All you need to do are the following three things:

    1. Add the following to top of your JSP:

      <%@page pageEncoding="UTF-8" %>
      

      This will set the response encoding to UTF-8 and set the response header to UTF-8.

    2. Create a Filter which does the following in doFilter() method:

      if (request.getCharacterEncoding() == null) {
          request.setCharacterEncoding("UTF-8");
      }
      chain.doFilter(request, response);
      

      This will make that the POST request body will be processed as UTF-8.

    3. Change the <Connector> entry in Tomcat/conf/server.xml as follows:

      <Connector (...) URIEncoding="UTF-8" />
      

      This will make that the GET query strings will be processed as UTF-8.

    See also:

    • Unicode – How to get characters right? – contains practical background information and detailed solutions for Java EE web developers.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application running in tomcat that has a bunch of configuration files
I have a J2EE-based system which is running currently on Apache Tomcat. We are
I have configured Tomcat 6 to serve Perl CGI scripts. That part is well
I'm running tomcat and have some jsp pages that display a subset of a
I have a tomcat instance setup but the database connection I have configured in
I have configured Tomcat to use LDAP / AD. How can I get more
In tomcat 6 i have a servlet running openbluedragon, everything compiles and servers up
I have two applications under tomcat/webapps folder. tomcat/webapps/App1 tomcat/webapps/App2 Both applications share the same
I have apache 2.2 and tomcat 5.5 running on a Windows XP machine. Which
I have two web applications running in the same Tomcat Instance. In one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.