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 6227449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:14:03+00:00 2026-05-24T09:14:03+00:00

I have a problem in my Java webapp. Here is the code in index.jsp:

  • 0

I have a problem in my Java webapp.

Here is the code in index.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<% request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>

        <form action="index.jsp" method="get">
            <input type="text" name="q"/>
        </form>

        Res: <%= request.getParameter("q") %>
    </body>
</html>

When I wireshark a request, my browser sends this header:

GET /kjd/index.jsp?q=%C3%A9 HTTP/1.1\r\n
...
Accept-Charset: UTF-8,*\r\n

And the Tomcat server returns me this:

Content-Type: text/html;charset=UTF-8\r\n

But if I send “é”(%C3%A9 in UTF-8) in my form, “é” is displayed instead.

What I understand is that the browser sends an “é” encoded with UTF-8 (the %C3%A9).

But the server interpret this as ISO-8859-1. So the %C3 is decoded as à and %A9 as ©, and then sends back the response encoded in UTF-8.

In the code, the requests should be decoded with UTF-8:

request.setCharacterEncoding("UTF-8");

But, if I send this url:

http://localhost:8080/kjd/index.jsp?q=%E9

the “%E9” is decocded with ISO-8859-1 and an “é” is displayed.

Why isn’t this working? Why requests are decoded with ISO-8859-1?

I’ve tried it on Tomcat 6 and 7, and on Windows and Ubuntu.

  • 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-24T09:14:04+00:00Added an answer on May 24, 2026 at 9:14 am

    The request.setCharacterEncoding("UTF-8"); only sets the encoding of the request body (which is been used by POST requests), not the encoding of the request URI (which is been used by GET requests).

    You need to set the URIEncoding attribute to UTF-8 in the <Connector> element of Tomcat’s /conf/server.xml to get Tomcat to parse the request URI (and the query string) as UTF-8. This indeed defaults to ISO-8859-1. See also the Tomcat HTTP Connector Documentation.

    <Connector ... URIEncoding="UTF-8">
    

    or to ensure that the URI is parsed using the same encoding as the body1:

    <Connector ... useBodyEncodingForURI="true">
    

    See also:

    • Unicode – How to get the characters right? – JSP/Servlet request

    1 From Tomcat’s documentation (emphasis mine):

    This setting is present for compatibility with Tomcat 4.1.x, where the
    encoding specified in the contentType, or explicitly set using
    Request.setCharacterEncoding method was also used for the parameters
    from the URL. The default value is false.


    Please get rid of those scriptlets in your JSP. The request.setCharacterEncoding("UTF-8"); is called at the wrong moment. It would be too late whenever you’ve properly used a Servlet to process the request. You’d rather like to use a filter for this. The response.setCharacterEncoding("UTF-8"); part is already implicitly done by pageEncoding="UTF-8" in top of JSP.

    I also strongly recommend to replace the old fashioned <%= request.getParameter("q") %> scriptlet by EL ${param.q}, or with JSTL XML escaping ${fn:escapeXml(param.q)} to prevent XSS attacks.

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

Sidebar

Related Questions

I recently have a problem that my java code works perfectly ok on my
I have a problem with a specific java client library. Here is the situation:
I have a problem with Tomcat 5.5 and Java EE webapp libraries. I'm using
Here's the problem: I have a java dynamic web project under source control and
I have problem with .css file on my JSP page. My page looks like
Hello I am a Java web app developer I have a problem, I would
I have a problem using the Java search function in Eclipse on a particular
I have a problem with my Java progam suddenly exiting, without any exception thrown
I have a little Java problem I want to translate to Python. Therefor I
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc

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.