JSP中的多部分表单,Glassfish中的编码问题

JSP中的多部分表单,Glassfish中的编码问题,jsp,servlets,character-encoding,glassfish,multipartform-data,Jsp,Servlets,Character Encoding,Glassfish,Multipartform Data,我使用Eclipse和Glassfish从jsp/servlet中获取无效字符 如果我输入“pêche”,我会得到“pêches”。这就是编码问题。我试了好几次,都没用 我试图添加一个过滤器() 我尝试在web.xml()中添加jsp属性 我试图通过请求更改java代码中我自己的字符编码 我尝试添加VM参数(),但无法添加,原因是() 我将这个“accept=“UTF-8”accept charset=“UTF-8”添加到我的 我在sun-web.xml和glassfish-web.xml中

我使用Eclipse和Glassfish从jsp/servlet中获取无效字符

如果我输入“pêche”,我会得到“pêches”。这就是编码问题。我试了好几次,都没用

  • 我试图添加一个过滤器()
  • 我尝试在web.xml()中添加jsp属性
  • 我试图通过请求更改java代码中我自己的字符编码
  • 我尝试添加VM参数(),但无法添加,原因是()
  • 我将这个“accept=“UTF-8”accept 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>

....

还有其他建议吗?

尝试添加以下内容:

<%@ 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>
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");


此外,测试POST和GET表单,因为它们的处理方式不同。accept属性也为浏览器提供信息。(例如,不获取HTML实体。)

最后,它似乎是一个Glassfish bug:


用这个问题解决得非常好:
新字符串(s.getBytes(“iso-8859-1”),“UTF-8”)()

我刚刚遇到了同样的问题。我想您可以在glassfish-web.xml中临时设置:

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


这对我很有用。

不起作用,我仍然会遇到奇怪的角色。无论如何谢谢你;)还有其他想法吗?我试着添加这个我在sun-web.xml和glassfish-web.xml中添加了“”,但仍然不起作用…如果没有人给出有用的答案,请禁用一些servlet过滤器,或者最好创建一个新的测试项目:(很抱歉,通过以下方式解决了此问题:…WEB-INF\glassfish-WEB.xml及其内容