brakebg
brakebg

Reputation: 414

chinese words in request (jsp - servlet)

I m having a html form with input field, so when is used english for the input there is no problem but using chinese words i got some incorrect string in the servlet, what encoding i m suppose to use and how to set it?

in the html form

<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
...
 <form method="post" action="<%= action %>"  accept-charset="UTF-8"> 

in the servlet

 String charset = request.getCharacterEncoding();
// here charset is always null
 String shareContent = request.getParameter("content");

For example input : 朋友你好 in servlet come : "æå你好"

Any idea?

Upvotes: 1

Views: 974

Answers (1)

Kent
Kent

Reputation: 195269

can you try if this works for you:

request.setCharacterEncoding( "UTF-8 "); 

also you may want to add a filter to do the encoding on all request/response.

Upvotes: 1

Related Questions