JSP中的多部分表单,Glassfish中的编码问题 [英] Multipart form in JSP, encoding problems in Glassfish
问题描述
如果我输入Pêche,就会得到Páches。所以,这是编码问题。我尝试了几个想法,没有任何工作。
- 我试着添加一个过滤器(编码JSP中的问题)
- 我尝试在web.xml中添加jsp属性()
- 我尝试在java代码中通过request.setCharacterEncoding(UTF-8); / li>
- 我尝试添加VM参数(无法将glassfish 3.1中的ISO-8859-1字符集更改为UTF-8 ),但我不能因为这个()
- 我向
- 添加了accept =UTF-8accept-charset =UTF-8我添加了
< parameter-encoding sun-web.xml和glassfish-web.xml中的默认字符集=UTF-8/>
我还是得到了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-Typecontent =text / html; charset = UTF-8/>
< title> ....< / title>
< / head>
< body>
< form action =< c:url value =/ form / edit/> method =postenctype =multipart / form-data>
< input type =textid =templateNamename =templateName/>
< br />
< input type =submitvalue =Validerclass =button button_blue margin_button_form/>
< / form>
< / body>
< / html>
其他建议?
最后,它似乎是一个Glassfish错误: https: //java.net/jira/browse/GLASSFISH-18516
用下面的方法解决了这个问题: new String(s.getBytes( iso-8859-1),UTF-8);
( https:// stackoverflow。 com / a / 549634/1458542 )
I'm getting invalid character from my jsp/servlet using Eclipse and Glassfish.
If I enter "Pêche" I get "Pêches". So, this is encoding problem. I tried several thinks and nothing works.
- I tried to add a filter (Encoding problems in JSP)
- I tried to add jsp properties in web.xml (Unable to change charset from ISO-8859-1 to UTF-8 in glassfish 3.1)
- I tried to change the character encoding my self in java code by request.setCharacterEncoding("UTF-8");
- I tried to add VM arguments (Unable to change charset from ISO-8859-1 to UTF-8 in glassfish 3.1) but I cannot because of this (Eclipse - No server found in Run Configurations)
- I added this " accept="UTF-8" accept-charset="UTF-8" " to my
- I added
<parameter-encoding default-charset="UTF-8"/>
in sun-web.xml and glassfish-web.xml
I still get Mojibake.
Here is my servlet code:
String name = (String) request.getParameter("templateName");
Here is my jsp content:
<%@ 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>
Any other suggestion?
At the end, it seems to be a Glassfish bug: https://java.net/jira/browse/GLASSFISH-18516
Solved awfully with this: new String (s.getBytes ("iso-8859-1"), "UTF-8");
(https://stackoverflow.com/a/549634/1458542)
这篇关于JSP中的多部分表单,Glassfish中的编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!