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

  • SEARCH
  • Home
  • 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 7653047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:55:36+00:00 2026-05-31T11:55:36+00:00

I’m trying to POSt a UTF-8 string to my servlet (hosted in TomCat) but

  • 0

I’m trying to POSt a UTF-8 string to my servlet (hosted in TomCat) but the string read on the server side is not UTF-8. I’ve verified via firebug that the ajax header’s content-type has the utf-8 encoding set. I’m posting “MÉXICO” to the server but I’m receiving “MÉXICO”.

$.ajaxSetup({ 
    scriptCharset: "utf-8" , 
    contentType: "application/x-www-form-urlencoded; charset=UTF-8"
});


$.ajax({
  url: "SetData",
  type: 'POST',
  data: 'MÉXICO',
  success: function(){
      console.log('Data set');
  }
});

Here’s the java code in the servlet

request.setCharacterEncoding("UTF-8");
BufferedReader reader = new BufferedReader( new InputStreamReader( request, "UTF-8" ) );        
char[] chr = new char[5];
reader.read( chr );
builder.append( chr );

UPDATE 1

I changed the posting data in js to encodeURIComponent(‘MÉXICO’) but the server still reads “MÉXICO”.

But, if I get the string value of encodeURIComponent(‘MÉXICO’) i.e. ‘M%C3%89XICO’ it works!
I’m zapped! Any idea why this should work?

$.ajax({
  url: "SetData",
  type: 'POST',
  //data: 'MÉXICO', ** does not work
  //data: encodeURIComponent('MÉXICO'),  ** does not work
  data: 'M%C3%89XICO',  //works !!!!
  success: function(){
      console.log('Data set');
  }
})

;

  • 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-31T11:55:37+00:00Added an answer on May 31, 2026 at 11:55 am

    I don’t understand what are you doing and what kind of request parameter are you sending. Shouldnt code be something like that:

    ...
    data:{key:'MÉXICO'},
    ...
    

    OR

    ...
    data:{key:encodeURIComponent('MÉXICO')},
    ...
    

    AND in servlet

    ...
    request.getParameter('key')
    ...
    

    OR

     stringURLDecoder.decode(
                                 request.getParameter('key').toString(),
                                 'UTF-8'
                            );
    

    Or I didn’t understand anything (If this is the case sorry :/)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.