Reputation: 1725
I have an application with Struts 1.2 and in a .jsp I've created a form using html tag, this is part of my code:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
...
<html:form action="/myAction" method="post">
...
<display:table name="ListOfEntries" sort="external" requestURI="/myEntryAction.do" uid="row">
...
<display:column titleKey="label.label" sortable="true" sortProperty="label">
<span id="staticlabel<c:out value="${row.id}" />">
<bean:write name="row" property="label" />
</span>
<html:text name="MyEntryForm" property="editedEntry.label" value="${row.label}" disabled="true" style="display:none" size="35"/>
</display:column>
So, when a edit an entry with a special character Ç
, in my MyEntryForm
I get it as Ã
.
Thanks in advance.
UPDATE: I forgot to mention that I'm using Weblogic.
Upvotes: 1
Views: 3546
Reputation: 1083
I see here several possible issues and solutions.
1) In order to correctly decode an HTML file, your should tell to your browser what encoding to use. You can tell it to him by setting the charset parameter or by setting meta tag. In your HTML, add this meta tag and see if that makes it look right in your browser:
for HTML4: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
for HTML5: <meta charset="utf-8">
2) The HTML meta tag is ignored when the page is served over HTTP. It's only been used when the page is by the client saved as a HTML file on local disk system and then opened by a file:// URI in browser.
Therefore it can be that HTTP request body encoding is apparently not been set to UTF-8. The request body encoding needs to be set by
request.setCharacterEncoding("UTF-8");
3) Change the database connection encoding
Following command should be used always once after opening the database connection to UTF-8:
...
mysql_connect();
mysql_query("SET NAMES 'utf8'");
4) Check the encoding of your database. You can change the encoding of the database with:
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
5) Also the file should be recorded in UTF-8 format. For example, in Eclipse: left-click on the file -> Properties -> Check out -> Text file encoding. Or do it in Notepad++.
So these are the most common issues. If it will not work, then provide us please with further information on your issue. But the main idea is actually always the same: if you are bringing different tools together and combine them, every of them should know what encoding is used in the another tool. And many of the problems are caused by one tool misunderstanding what encoding is actually used by another tool.
Upvotes: 2
Reputation: 1725
I found what was the problem.
In the question I forgot to mention that I'm using Weblogic as server. Debugging with Firefox or Chrome I checked that the request from my browser was correct, with the correct character, so it had to be the server.
In my project, I have a weblogic.xml, with this content:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<description>My Struts Application</description>
<context-root>RootOfMyApplication</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
And I adding this the problem was solved:
<charset-params>
<input-charset>
<resource-path>/*</resource-path>
<java-charset-name>UTF-8</java-charset-name>
</input-charset>
</charset-params>
Upvotes: 1