Java handling special character in request.getParameter

删除回忆录丶 提交于 2020-01-03 03:40:08

问题


I am trying to get parameter in my java class that contain a special character. I have added it as follows

   <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> 

I have these two parameters: (1)3 –days System Admin (6EE SP1) training at VMware Bangalore location (2)Daiichi:eDossier – Phase1 new_6500004691

After submitting the page i get the perfect result,but two parameter names gets change as below:

(1)Daiichi:eDossier ââ¬â Phase1 new_6500004691 (1)3 âdays System Admin (6EE SP1) training at VMware Bangalore

Please suggest


回答1:


Try setting request.setCharacterEncoding("UTF-8") before the first call to getParameter().

If that doesn't work, have a look at your Tomcat config.




回答2:


I know what's your problem: Your application server/servlet container is not configured to support unicode characters.

You will have to configure you application server/servlet container to support UTF Encoding. Tomcat Example has been answered in this SO question.

Another alternative is to write a Character Encoding Filter and configure it in your web application.



来源:https://stackoverflow.com/questions/10895743/java-handling-special-character-in-request-getparameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!