tomcat5中,因為眾所周知的原因,為了保證get/post數據都采用相同的UTF8編碼,我們在server.xml中進行了如下設置:
maxSpareThreads="75" enableLookups="false" redirectPort="8443"
acceptCount="100" debug="99" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="UTF-8"/>
這里指定了get時候的數據編碼。但是,當使用IIS作為webserver轉發servlet/jsp請求給Tomcat時候,這個設置卻失效了。其實原因很簡單:IIS是通過AJP協議,把請求轉發到Tomcat監聽的8009端口上的,所以這里針對8080的設置自然就無效了。正確的方法是進行下面的設置:
debug="0" protocol="AJP/1.3" URIEncoding="UTF-8"/>
雖然是小問題,卻花了我幾個小時才想到。
posted @
2007-12-03 14:53 kelly 閱讀(536) |
評論 (0) |
編輯 收藏
一、請求結果的亂碼:
解決辦法:在顯示中文字符串前加上 request.setCharacterEncoding("gbk");
或者:在獲取字符串str后使用str = new String(str.getBytes("ISO-8859-1"),"GB2312");轉換
ISO-8859-1是默認的字符編碼
解決辦法:
1、項目已打包到web服務器:
找到 %TOMCAT_HOME%\conf\server.xml文件,將此文件的代碼段末尾加 入 URIEncoding="gbk",結果如下所示:
<Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="gbk"/>
2、開發過程中:
找到 %project_name%\Tomcat\conf\server.xml文件,刪除文件中的備注,增加URIEncoding="gbk",結果如下所示:
<Connector acceptCount="10" connectionTimeout="60000" maxThreads="75" minSpareThreads="5" port="8080" URIEncoding="gbk"/>
二、處理響應結果的亂碼..
1.在servlet中 response.setContentType("text/html;charset=GB2312");
2.在jsp中 <%@page contentType="text/html;charset=GB2312"%>
3.在html中 <head><META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=GB2312"></head>
posted @
2007-12-03 14:40 kelly 閱讀(280) |
評論 (0) |
編輯 收藏
一、提交中文是使用javascript的函數:encodeURIComponent()進行編碼,
例如:
String
param=encodeURIComponet("param");
然后到服務器端使用UTF-8編碼提取參數:
request.setCharacterEncoding("UTF-8");
String str = request.getParameter("param");
然后使用下面的方式進行解碼:
java.net.URLDecoder.decode(str,"UTF-8")
這樣就可以得到正確的參數。
posted @
2007-09-20 12:22 kelly 閱讀(1488) |
評論 (0) |
編輯 收藏
<%
'先下載遠程圖片
url="
http://www.baidu.com/img/logo.gif" '遠程圖片地址
savepath="e:\www\www9551cn" '保存路徑
'給文件重命名
randomize
ranNum=int(999*rnd)
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
'文件重命名結束
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
img = xmlhttp.ResponseBody
text=xmlhttp.ResponseText
set xmlhttp=nothing
set objAdostream=server.createobject("ADODB.Stream")
objAdostream.Open()
objAdostream.type=1
objAdostream.Write(img)
objAdostream.SaveToFile(savepath&filename&".jpg")
objAdostream.SetEOS
set objAdostream=nothing
'文件下載結束
%>
posted @
2007-04-05 13:12 kelly 閱讀(1513) |
評論 (3) |
編輯 收藏
在JSP的查詢或者插入數據庫的時候總會遇到亂碼的問題,下面給出兩種解決方案:
1、在頁面中加上 request.setCharacterEncoding("utf-8");
2、String name=new String(request.getparameters("name").getBytes("ISO8859_1"),"utf-8")
posted @
2007-03-19 15:37 kelly 閱讀(262) |
評論 (0) |
編輯 收藏