3

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 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?

Community
  • 1
  • 1
Jon
  • 218
  • 7
  • 18

4 Answers4

3

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)

Community
  • 1
  • 1
Jon
  • 218
  • 7
  • 18
1

I just faced the same issue. I guess you can temporarily set this in glassfish-web.xml:

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

This works for me.

arpadf
  • 413
  • 3
  • 13
0

Try to add this:

<%@ 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>

And in your Servlet add this:

request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
stark
  • 119
  • 1
  • 3
  • 10
  • Not working, I still get strange characters. Thanks any way ;) Any other ideas? – Jon May 14 '13 at 10:48
0

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

Furthermore test POST and GET forms as they are handled differently. The accept attribute is informative to the browser too. (Not getting HTML entities for instance.)

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138