3

我从使用Eclipse和Glassfish的jsp/servlet中获取无效字符。JSP中的多部分表单,Glassfish中的编码问题

如果我输入“Pêche”,我会得到“PÊches”。所以,这是编码问题。我尝试了几个想法,没有任何工作。

我还是得到了Mojibake。

这里是我的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> 

任何其他建议?

回答

0

尝试添加此:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
</head> 

而且在你的servlet补充一点:

request.setCharacterEncoding("UTF-8"); 
response.setCharacterEncoding("UTF-8"); 
response.setContentType("text/html; charset=UTF-8"); 
+0

不工作,我仍然得到奇怪的字符。感谢任何方式;)任何其他想法? – Jon 2013-05-14 10:48:49

+0

无法在servlet中添加这些行;) – Jon 2013-05-14 10:56:57

0

http://www.devsniper.com/glassfish-tips-default-encoding/

而且测试POST和GET的形式,因为它们的处理方式不同。 accept属性也是浏览器的信息。 (没有获得例如HTML实体)

+0

我试图添加这个 Jon 2013-05-14 11:06:40

+0

我添加了““在sun-web.xml和glassfish-web.xml中仍然无法正常工作... – Jon 2013-05-14 11:13:18

+0

如果没有人提供有用的答案,请禁用一些servlet过滤器,或者更好地创建一个新的测试项目。 :(对不起 – 2013-05-14 11:15:08

1

我只是面临着同样的问题。我猜你可以在glassfish-web.xml中临时设置它:

<parameter-encoding default-charset="UTF-8"></parameter-encoding> 

这对我有用。

+0

解决了这个.... WEB-INF \ glassfish-web。xml with content \t cljk 2013-11-04 14:04:35