There are a lot of questions on StackOverFlow on this theme:
- Handling Character Encoding in URI on Tomcat
- Why the character is corrupted when use request.getParameter() in java?
- request.getParameter() does not display properly character encoding in java servlet
- 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:
- 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">
- In Eclipse->Preferances->General->Workspace->Text files encoding set to UTF-8
Database encoding is set to:
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
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"/>
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 ??