0

There are a lot of questions on StackOverFlow on this theme:

  1. Handling Character Encoding in URI on Tomcat
  2. Why the character is corrupted when use request.getParameter() in java?
  3. request.getParameter() does not display properly character encoding in java servlet
  4. Character encoding problems with tomcat

There is also a link in Tomcat Wiki on this issue: http://wiki.apache.org/tomcat/FAQ/CharacterEncoding

So I didn't know what title to my question I should write. Maybe you would help me with this one two.

The problem I came up with: when text with cyrillic characters comes from requests I'm getting the following request parameter value: to ÐÐ¸Ð·Ð½ÐµÑ Ð¸ ÑинанÑÑ.

So what I have for this moment:

  1. All jsp files have UTF-8 encdoing like so:
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  1. In Eclipse->Preferances->General->Workspace->Text files encoding set to UTF-8
  2. Database encoding is set to: DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;

  3. In \apache-tomcat-7.0.57\conf folder server.xml one of the connectors was modified to:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>

  1. Create Encoding filter with doFilter method:

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest)request;
        String requestEncoding = request.getCharacterEncoding();
        if (requestEncoding == null) {
            request.setCharacterEncoding(encoding);
        }
        chain.doFilter(request, response);
    }
    

When reading from jsp I've also tried to fetch parameters in different ways like:

 <a href="<c:url value="controller?command=viewFaculty"> 
<c:param name="name" value="${faculty.name}"/> </c:url>">${faculty.name}</a>

or

<a href="<c:url value="controller?command=viewFaculty"> <c:param name="name" value="${faculty.name}"/>

And I still get this ugly characters. Would you help me with some advice ??

Community
  • 1
  • 1
marknorkin
  • 3,904
  • 10
  • 46
  • 82

1 Answers1

0

I solve my problem. The issue was that I edited not the original server.xml. I've noticed that tomcat has appeared in Eclipse project explorer as a bookmark to project called Servers. And some files lies in him, such as:

  1. catalina.policy
  2. catalina.properties
  3. context.xml
  4. web.xml
  5. tomcat-users.xml and
  6. server.xml

So it happened that tomcat already have preconfigured files and it just strange that edited by myself file server.xml in \apache-tomcat-7.0.57\conf folder differs from the one that lies in this project.

At the start of the question I've linked some answears to this problem and at the end of my post I want to share the one that I found recently, that seems to me as the best guide to this problem: How to get UTF-8 working in Java webapps?

Community
  • 1
  • 1
marknorkin
  • 3,904
  • 10
  • 46
  • 82