日期:2014-05-17  浏览次数:20666 次

jsp从地址栏request来的变量的编码问题
request.setCharacterEncoding("UTF-8");

不管用。
对于字符窜,接受后能够正常显示。比如
String content = request.getParameter("var");//content ="some stuff"
if(content=="some stuff"){}
的条件却为假。这个是怎么回事?

------解决方案--------------------
对于jsp从地址栏request来的变量的编码问题,可以修改tomcat的字符编码为UTF-8格式,或者在servlet或者action中做转换,比如
String content = request.getParameter("var");
String content1 = new String(content.getBytes("iso-8859-1"),"utf-8");

而对于字符串判定,用equals,而不是==
String content = request.getParameter("var");//content ="some stuff"
if(content.equals("some stuff")){}
------解决方案--------------------
引用:
对于jsp从地址栏request来的变量的编码问题,可以修改tomcat的字符编码为UTF-8格式,或者在servlet或者action中做转换,比如
String content = request.getParameter("var");
String content1 = new String(content.getBytes("iso-8859-1"),"utf-8");

而对于……

------解决方案--------------------
字符串比较最好用equal
------解决方案--------------------
字符串比较不能用==的。。用equals
------解决方案--------------------