我使用 Eclipse 和 Glassfish 从 jsp/servlet 中获取无效字符。
如果我输入“Pêche”,我会得到“Pàches”。所以,这是编码问题。我尝试了几种想法,但没有任何作用。
- 我尝试添加一个过滤器(JSP中的编码问题 https://stackoverflow.com/questions/932559/encoding-problems-in-jsp)
- 我尝试在 web.xml 中添加 jsp 属性(无法在 glassfish 3.1 中将字符集从 ISO-8859-1 更改为 UTF-8 https://stackoverflow.com/questions/6279504/unable-to-change-charset-from-iso-8859-1-to-utf-8-in-glassfish-3-1)
- 我尝试通过 request.setCharacterEncoding("UTF-8"); 更改 java 代码中我自己的字符编码
- 我尝试添加虚拟机参数(无法在 glassfish 3.1 中将字符集从 ISO-8859-1 更改为 UTF-8 https://stackoverflow.com/questions/6279504/unable-to-change-charset-from-iso-8859-1-to-utf-8-in-glassfish-3-1)但我不能因为这个(Eclipse - 在运行配置中找不到服务器 https://stackoverflow.com/questions/11144068/eclipse-no-server-found-in-run-configurations)
- 我将此“accept =“UTF-8”accept-charset =“UTF-8””添加到我的
- I added
<parameter-encoding default-charset="UTF-8"/>
在 sun-web.xml 和 glassfish-web.xml 中
我仍然得到莫吉巴克。
这是我的 servlet 代码:
String name = (String) request.getParameter("templateName");
这是我的jsp内容:
<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>....</title>
</head>
<body>
<form action="<c:url value="/form/edit" />" method="post" enctype="multipart/form-data">
<input type="text" id="templateName" name="templateName" />
<br />
<input type="submit" value="Valider" class="button button_blue margin_button_form"/>
</form>
</body>
</html>
还有其他建议吗?
最后,这似乎是 Glassfish 的 bug:https://java.net/jira/browse/GLASSFISH-18516 https://java.net/jira/browse/GLASSFISH-18516
解决得很糟糕:new String (s.getBytes ("iso-8859-1"), "UTF-8");
(https://stackoverflow.com/a/549634/1458542 https://stackoverflow.com/a/549634/1458542)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)