我的情况:
不加 page 的 contentType 属性,输出字符串时:
String title = new String(su.getRequest().getParameter("title").getBytes, "ISO-8859-1");
out.print(title);
这样可以保证 print 的字符串和 JSP 的静态内容都不会乱码。(所有文件均使用 ASCII GB2312 编码保存)。
只要加入 page 的 contentType 属性,或加入 response.setCharacterEncoding() 方法都会有问题,print 和 JSP 静态内容都会至少有一方变成 ?。
不加 page 的 contentType 属性,输出字符串时:
String title = new String(su.getRequest().getParameter("title").getBytes, "ISO-8859-1");
out.print(title);
这样可以保证 print 的字符串和 JSP 的静态内容都不会乱码。(所有文件均使用 ASCII GB2312 编码保存)。
只要加入 page 的 contentType 属性,或加入 response.setCharacterEncoding() 方法都会有问题,print 和 JSP 静态内容都会至少有一方变成 ?。
解决方案 »
- The server encountered an internal error (Dispatch[/list] to method listIni returned an exception) that prevented it from fulfil
- 我怎么查看tomcat中jsp和servelt的版本?
- 关于资源访问的问题
- 关于动态创建树的问题
- 北京新手搞java Web开发,最低多少钱薪水?
- 还有得补救吗?
- 珠海的IT现状!
- 请教javabeans小问题
- 关于jsp中文显示的问题?在线等,急?
- springMVC提示No mapping found for HTTP request错误
- jbuilder9是不是有问题啊 明明有类 它说没有
- JSP中使用static 变量的问题?
不进行转换就可以,转了就不行
tomcat相反
中文xp pro
mysql 4.1.16
网页编码gbk
String s = new String(m_binArray, i, (j - i) + 1);
也就是,如果你运行平台运行在一个gb编码的平台的话,就不需要转码
但是如果你是运行在一个非gb编码的平台的话,就要转码!
转码的规则是
new String(su.getRequest().getParameter("").getBytes(平台的默认编码),"GBK");
接下来的事情就是祝你好运!
加入
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gb2312</param-value>
</init-param>
</filter>
然后再使用request.getParameter("...");
<form name="frma" method="post" action="weng.jsp" enctype="multipart/form-data">
我用的,也没加转换,就好用了