我正在基于 Struts2(和 Struts2-jquery 插件,但我不认为这是问题的原因)扩展现有代码。
我在 Internet Explorer 9 中发现了一个奇怪的行为(我不知道以前版本的 IE 是否也存在同样的问题),但在 FireFox 中却没有出现。
我有一个页面,其中包含一些输入字段和一个用于在服务器上上传文件的上传功能。当用户上传文件时,该文件通过表单提交发送到服务器,然后操作返回到同一页面(重新加载页面)。如果我使用带重音的字母填充输入框,则当表单提交后重新加载页面时,出现的不是带重音的字母,而是一个“正方形”(它是 �
)。这种情况仅发生在 IE 中,而不是 FireFox 中(其中字符与提交之前保持相同)。
在web.xml
和struts.xml
文件中,没有JSP的编码配置。
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<s:form id="actionForm" name="actionForm"
theme="simple" cssClass="yform"
action="changeAction" acceptcharset="UTF-8">
<table>
<tr>
<td>field1</td>
<td>
<s:textfield id="field1" name="field1" maxlength="2048" value="%{field1}" disabled="false" size="98" required="true" />
</td>
</tr>
<tr>
<td><s:file name="docFacFileUploaded" size="50" /></td>
<td>
<sj:submit targets="main_section" id="uploadFileButton" value="File upload" button="true" indicator="indLoad" />
<img id="indLoad" src="indicator.gif" alt="Loading..." style="display:none" />
</td>
<tr>
</tr>
<td>field2</td>
<td>
<s:textfield id="field2" name="field2" maxlength="2048" value="%{field2}" disabled="false" size="98" required="true" />
</td>
</tr>
<tr>
<td>
<sj:submit targets="main_section" id="salvaButton" value="Salva" button="true" indicator="ind" />
<img id="ind" src="indicator.gif" alt="Loading..." style="display:none" />
</td>
</tr>
</table>
</s:form>
最佳答案
您可能使用的字符编码与浏览器设置的字符编码不同。例如,UTF-8 unicode 与 ISO-8859-1 存在一些差异。国外网站更糟糕。通常浏览器可以自动检测它,但它似乎并不总是有效。
转到 View 菜单>字符编码并尝试其中的选项,直到找到正确显示的选项。
<%page contentType="text/html" pageEncoding="UTF-8"%>
或
header('Content-Type: text/html; charset=UTF-8');
关于java - 在 IE 中提交后出现奇怪的行为字符(在 FF 中不会发生),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14684519/