I've a Struts2 application with some encoding problems. My JSP page displays 2 forms; when I send the first one (a simple, regular form, which reloads the full page), non-standard characters such as á
or ñ
are sent and shown correctly. However, when I do the same with the second form (which is sent via AJAX), the data gets corrupted (Ãí
, Ã!
and so on).
main.jsp:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
...
<s:head theme="ajax"/>
</head>
<body>
<!-- This form is sent via regular HTTP request -->
<s:form theme="simple" enctype="multipart/form-data">
<s:textfield key="field1" name="var1"/>
<s:submit key="send" action="SAVE_ACTION"/>
</s:form>
<div id="ajaxContainer">
<jsp:include file="ajax-part.jsp"/>
</div>
</body>
</html>
ajax-part.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!-- This form is sent via AJAX -->
<s:form enctype="multipart/form-data" theme="ajax" action="AJAX_ACTION" acceptcharset="UTF-8">
<s:textfield key="field2" name="var2"/>
<s:submit key="send" targets="ajaxContainer"/>
</s:form>
As you can see, I've set UTF-8 encoding everywhere. I've also checked that the files are actually UTF-8 encoded. And DOJO (which is used for the AJAX requests) is configured in UTF-8 too, because <s:head theme="ajax"/>
becomes:
<script language="JavaScript" type="text/javascript">
// Dojo configuration
djConfig = {
baseRelativePath: "/myApp/struts/dojo",
isDebug: false,
bindEncoding: "UTF-8",
debugAtAllCosts: false
};
</script>
I'm running the application on a Tomcat 6 server; adding the -Dfile.encoding=UTF-8
parameter makes no difference (appart from the log files being recorded in UTF-8 instead of ISO-8859-1).
It happens both in Google Chrome and IE8, so I guess the browser has nothing to do with the problem, it must be something in the webapp.
What am I missing? What can I change to process correctly my AJAX posts?