// set the encoding for the input parameters request.setCharacterEncoding("UTF-8"); String test = request.getParameter("test"); if( test==null ) test = "input parameter 'test' was null"; // set the content type AND encoding for the output response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.print( test );这一句写了啊. request.setCharacterEncoding("UTF-8");request.getParameter("test");取回来应该是正确的吧. 奇怪的事就是不行.---初学者
request.setCharacterEncoding("UTF-8");
String test = request.getParameter("test");
if( test==null ) test = "input parameter 'test' was null"; // set the content type AND encoding for the output
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.print( test );这一句写了啊.
request.setCharacterEncoding("UTF-8");request.getParameter("test");取回来应该是正确的吧.
奇怪的事就是不行.---初学者
response.setContentType(CONTENT_TYPE);如果直接写在页面上的中文是正常的.
只是从URL取回的包含中文参数,就不行了.我猜应该是request.setCharacterEncoding()的问题.---初学者
{
try
{
String str_1 = temp;
byte[] str_2 = str_1.getBytes("ISO8859-1");
String str_3 = new String(str_2);
return str_3;
}
catch(Exception e)
{
return temp;
}
}.................
out.println(changStr(userName));
................
真的行哦.犯糊涂了,这样request.setCharacterEncoding()还有什么用?---初学者
request.setCharacterEncoding(PAGEENCODING);
response.setCharacterEncoding(PAGEENCODING);
这两个是什么的干活?在网上查了一通,发现到处都是抄别人的,没一点新意.
能够说出自己的见解的非常少见.---初学者
if ( str != null ) {
try {
return new String( str.getBytes("iso-8859-1"), "GBK");
} catch ( Exception e ) {
return str;
}
}
return null;
}String userName = request.getParameter("userName");userName = getGBK(userName);我为这个东西也头疼了很久,虽然我不是初学者。 不过楼主也不要怪网上写文章的兄弟们,有些问题,不同的环境下解决方法不同,每个人的喜好不同,而恰恰他所能够解决问题的方法在我们的环境上不适用。 网络是个资源, 而不是total solution.
request.setCharacterEncoding(PAGEENCODING);
response.setCharacterEncoding(PAGEENCODING);
这样就解决问题的回答.应该肯定的是有人这样就解决了问题的.你说呢, xinhaitian---初学者
{
String str = null;
try{
str = new String(gbStr.getBytes("GBK"),"8859_1");
}catch(Exception e){}
return str;
}
public static String iso2Gb(String Str)
{
String str = null;
try{
str = new String(Str.getBytes("8859_1"),"GBK");
}catch(Exception e){}
return str;
}
2)在你的web.xml里加入如下几行: <filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>3)完成.2 get方式的解决办法
1) 打开tomcat的server.xml文件,找到以下区块,加入如下一行:
URIEncoding=”GBK”
完整的应如下:<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="GBK"
/>
2)重启tomcat,一切OK。
response.setCharacterEncoding(PAGEENCODING);我只是想问问这两边两个是干什么用的?
一个问题有N种解法,是我们要如何选择的问题.---初学者