JAVA通过JSP、SERVER获取的数据编码问题

        试着写JAVA,主要是要用LUCENE,很顺利的完成了索引写入,和查询,结果碰上了个编码问题。英文咋试咋行,中文死活搜不出来。输入数据的页面编码,服务器编码都设了,UTF-9,GBK等,总是不行。早上起来,继续找原因,终于,一句话让我知道原因了。“在TOMCAT中,由Request.getParameter() 得到的参数,编码方式都是ISO8859_1”,好吧,是我错了,写PHP好多年,刚知道JAVA是这么干的。知道原因,解决起来就简单了。一句话:request.setCharacterEncoding(“GB2312”);就好了。当然,也可以response.getParameter(“name”); String correctStr=new String(wrongStr.getBytes(“ISO8859_1”),”GB2312”);只不过比较啰嗦一点。搞定了,很开心,继续研究LUCENE。

This entry was posted in 技术文章. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>