How to pass Unicode characters as JSP/Servlet request.getParameter? -


after lot of trial , error still can't figure out problem. jsp, servlet, , database set accept utf-8 encoding, still whenever use request.getparameter on has two-byte characters em dash scrambled broken characters.

i've made manual submissions database , it's able accept these characters, no problem. , if pull text database in servlet , print in jsp page's form displays no problem.

the time i've found comes broken characters when try , display elsewhere after retrieving using request.getparameter.

has else had problem? how can fix it?

that can happen if request and/or response encoding isn't set @ all.

for requests, need configure @ servletcontainer level. it's unclear 1 you're using, in example tomcat that's done uriencoding attribute in <connector> element in /conf/server.xml.

<connector ... uriencoding="utf-8"> 

for post requests, need create filter mapped on desired url pattern covering post requests. e.g. *.jsp or /*. following job in dofilter():

request.setcharacterencoding("utf-8"); chain.dofilter(request, response); 

for html responses , client side encoding of submitted html form input values, need set jsp page encoding. add top of jsp (you've done given fact displaying utf-8 straight form db works fine).

<%@page pageencoding="utf-8" %> 

or prevent copypasting on every single jsp, configure once in web.xml:

<jsp-config>     <jsp-property-group>         <url-pattern>*.jsp</url-pattern>         <page-encoding>utf-8</page-encoding>     </jsp-property-group> </jsp-config> 

for source code files , stdout (ide console), need set ide workspace encoding. it's unclear 1 you're using, in example eclipse that's done setting window > preferences > general > workspace > text file encoding utf-8.

enter image description here

do note html <meta http-equiv> tags ignored when page served on http. it's considered when page opened local disk file system via file://. specifying <form accept-charset> unnecessary defaults response encoding used during serving html page form. see w3 html specification.

see also:


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -