本文介绍了JSP中的多部分表单,Glassfish中的编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我输入Pêche,就会得到Páches。所以,这是编码问题。我尝试了几个想法,没有任何工作。
- 我试着添加一个过滤器()
- 我尝试在web.xml中添加jsp属性(),但我不能因为这个(
用下面的方法解决了这个问题:
new String(s.getBytes( iso-8859-1),UTF-8);
()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中的编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!