0

i am trying to get UTF-8 string with using servlet, my code block is showing below;

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

but I could not get the utf-8 string , interesting chars is apperaing... Is there any way to get UTF-8 string ?

Poyraz
  • 359
  • 1
  • 5
  • 12
  • Which servlet container are you using? – Abhijeet Panwar Jul 25 '14 at 12:26
  • This is similar problem: http://stackoverflow.com/questions/3029401/java-servlet-and-utf-8-problem – alobodzk Jul 25 '14 at 12:30
  • How are the parameters passed to your servlet, form submit, AJAX, ? Are you passing UTF-8 characters?, what do you meain by "chars is appearing" – Ankit Jul 25 '14 at 12:50
  • I am pasing "barış" to jsp page with using text field, it is apperaing: barñÃÂ, String text = request.getParameter("text"); – Poyraz Jul 25 '14 at 13:05

1 Answers1

0

The problem could be that the string received by the servlet is not really in UTF-8. Make sure that the JSP calling the servlet is also in UTF-8. Try adding this at the top of your JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
David Levesque
  • 22,181
  • 8
  • 67
  • 82