作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||
browser 戀香 版主 發文: 3510 積分: 1 |
收藏文章? ||
太好了 .... 十分感謝 精靈 兄整理的這份資料 ... 這份文件是 Tomcat 5.0.19 中文參數傳遞的正解 ... 原本當初也想在書中特別提出來介紹的,但是當時己經進入排版階段 .. 在這邊我做幾項補充 ... 一般說來,我們在使用 Tomcat 4 透過 GET or POST 的方式傳參數時,通常都是使用 Filter 的方式來解決中文傳參數的問題。 但是到了 Tomcat 5.0.19 之後,解決中文傳遞參數時,就必須考慮是使用 GET or POST,兩種解決的方式不一樣。 如果是使用 GET 的方式傳遞時,就如同 精靈 兄 的文章所述,或者使用
;若是使用 POST 的方式時,就延用傳統一般解決中文的方式
不過當初我最後的做法是使用 Filter 的方式 Filter 的做法就是:先判斷是使用那種傳遞方式( GET or POST),假若是用 GET 的方式就採用第一種 code;若使用POST 方式,就採用第二種 code。
browser edited on 2005-03-16 15:15
|
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
發條盒子 問問題的麻煩傢伙 發文: 120 積分: 0 |
收藏文章? ||
request.setCharacterEncoding("Big5"); 我用這一行可以解決get和post的問題,這是為什麼呢? 反而我去設定了URIEncoding="ISO-8859-1"卻沒有什麼用也 環境tomcat5.0.16+j2sdk1.4.2_03+windows xp
browser edited on 2004-04-16 01:07
如果我能學好jsp就好了 我是新手,希望大家體諒我問的問題太白痴^^ 買書買到沒有錢錢 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||
jan 發文: 47 積分: 0 |
收藏文章? ||
我在server.xml中依照精靈前輩所說的這個設定修改了Connector Tag
SUBMIT中文時採用GET的方式依然結取到亂碼耶~~ 請問還有要注意什麼嗎? 我的平台: OS : Windows2003 Server SDK : Sun SDK 1.4.2_03-b02 Tomcat 5.0.19
jan edited on 2004-05-07 16:20
|
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:jan] | ||
browser 戀香 版主 發文: 3510 積分: 1 |
收藏文章? ||
jan wrote: 我是使用 URIEncoding="Big5" |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||
plutotw 井底蛙 發文: 358 積分: 2 |
收藏文章? ||
我們老師提的解決方案,用
測試結果在 windows 上是正常的 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
senshaw 發文: 1 積分: 0 |
收藏文章? ||
感謝~我發現tomcat 5中文參數問題後,遲遲不敢升級,現在見到曙光了 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:browser] |
sindylee 發文: 1 積分: 0 |
收藏文章? ||
請問若是在filter判斷是否為GET 或 POST 的話, 那麼 若是 POST method, 則可直接用 request.setCharacterEncoding 做掉, 若是 GET method, 該如何將處理完的結果存回 request , 然後傳送到 JSP 中呢? 因為不想在每支JSP 中去判斷及處理 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||
hcl 發文: 6 積分: 0 |
收藏文章? ||
想請教各位先進,小弟我依照上述方式改了設定,但是圖檔連結的檔名 是中文,那在TOMCAT5.0.19上面無法顯示,想請問一下該如何處理呢?
環境: WINDOWS 2000 SP4 + TOMCAT5.0.19 + IIS 5.0
hcl edited on 2004-07-16 15:47
|
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
prf 發文: 1 積分: 0 |
收藏文章? ||
好贴。 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:hcl] | ||
Jill_Yeh 眾裡尋他千百度 發文: 89 積分: 0 |
收藏文章? ||
hcl wrote: 若是搭配 IIS 的話, 不是 JAVA 的皆是由 IIS 來處理 所以你這個 <IMG> 基本上是透過 IIS 在傳遞 接下來就是中文的問題, IIS 理論上沒這個問題, 問題應該出在瀏覽器這端 若是你使用 IE, 則去選項設定那邊查看是否有開啟「永遠將 URL 傳送成 UTF8....」 這是我之前的經驗, 有錯誤請指正 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
shirley_wang 發文: 3 積分: 0 |
收藏文章? ||
如果是普通的form,用ISO-8859-1讀取沒問題。可是當form的enctype是multipart/form-data的時候,再用ISO-8859-1讀取字符串就出現問題。 那位大蝦能幫忙解決一下?萬分感謝! BR/Shirley |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
rawhead 發文: 42 積分: 0 |
收藏文章? ||
<Connector debug="0" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" port="80" redirectPort="8443" enableLookups="false" minSpareThreads="25" maxSpareThreads="75" maxThreads="150" maxPostSize="0" URIEncoding="ISO-8859-1"> </Connector> 我的Tomcat預設的port是8080 那我是要在 port是8080的<Connector.../> 直接加入URIEncoding="ISO-8859-1"就好 還是要把整段都寫進去? |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||
Sovina 發文: 3 積分: 0 |
收藏文章? ||
請問如果用URL來傳遞中文參數,應如何處理? 例如: URL --> http://127.0.0.1:8080/test/test.jsp?keyword=正常 因URL 不能傳遞中文, 所以我用了
來把中文ENCODE. 轉換后的URL --> http://127.0.0.1:8080/test/test.jsp?keyword=%A5%BF%B1%60 當我在另外一頁JSP 用
所顯示的是亂碼. 如何解決? 平台: winXP, Tomcat5.0.27 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||||||||
EVAzero 發文: 46 積分: 0 |
收藏文章? ||
看了好幾篇文, 對中文參數傳遞時會變亂碼終於有點頭緒, 所以就來分享一下, 其實用browser大大的方法是最簡單的解決方法, 建議初學者用這個先練習一下. 但就是要一個一個的改, 對於開發網站的不太好做, 所以分享一下我暫時的做法 os: Win2000 server + Tomcat 5.0.28 + JDK 1.4.2_07 *: 因為我都習慣用UTF-8, 所以檔案要是UTF-8格式(web.xml 和 server.xml 不用特意去改, 原本是怎樣就直接修改即可) 站台叫/mytest 參數傳遞可分為POST 和 GET [POST] 用Filter, Tomcat 已經做了個例子, 直接拿來用, 在/jsp-examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.class copy 到自己的站台/mytest/WEB-INF/classes/filters/裡,(如果package有變更時需要修改.java檔再編譯為.class來使用) 修改mytest/WEB-INF/web.xml, 新增以下的code
[GET] 就是用本title第一篇精靈大大的方法, 修改{tomcat}/conf/server.xml, 找到
直接接收即可 這樣, 基本上就解決了post和get的亂碼問題. PS. 在修改web.xml 和 server.xml 後一定要記得重開Tomcat [未解問題] 像shirley_wang 有提到, 用
[我有問題] browser wrote: 請問browser大大, 如何在Filter裡判斷GET 還是 POST 呢?
EVAzero edited on 2005-10-27 12:03
|
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:EVAzero] |
bmilk 發文: 32 積分: 1 |
收藏文章? ||
[我有問題] 請問browser大大, 如何在Filter裡判斷GET 還是 POST 呢? request.getMethod() |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:bmilk] |
多多 發文: 11 積分: 0 |
收藏文章? ||
bmilk wrote: 我沒弄錯的話… getMethod()是HttpServletRequest這個類別的方法… 可是在Filter中的 doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 傳入的是ServletRequest這個類別耶…所以應該不行這樣子判斷才對… |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||
swpoker 發文: 65 積分: 0 |
收藏文章? ||
這個我頁面是utf-8
然後用form傳遞都可以 然後用url傳中文時 先用javascript轉成utf-8 然後都可以了 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
valueyao 發文: 23 積分: 0 |
收藏文章? ||
这位大哥,我照你的方法把<connecter>快内添加了URIEncoding="ISO-8859-1,问题还是不能得到解决啊 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] |
Nievor 發文: 3 積分: 0 |
收藏文章? ||
我是個初學者,我很用心的把每個大大的回文都看了很幾遍,終於自己try出來了 使用post的方式的時候產生亂碼的問題,花了我很多時間 我把我的設定跟程式post出來給大家參考,希望遇到同樣狀況的版友可以快速解決 環境: WinXP SP1,Oracle 9i (9.0.1.1.1), Tomcat 5.0.16, JSP 設定步驟: Step1: 將tomcat安裝目錄下的conf/server.xml 此檔案叫出來編輯 找出你的網頁server的port那裡 一般安裝好是8080 port <Connector URIEncoding="Big5" port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true"/> URIEncoding="Big5" 是插進去的,編輯好後存檔即可 Step2: 在接收那一頁的jsp程式中加入 request.setCharacterEncoding("Big5"); 然後在抓值的地方用UTF-8 statement.setAsciiStream(1, new ByteArrayInputStream( (request.getParameter("Name")).getBytes("UTF-8")), (request.getParameter("Name")).getBytes("UTF-8").length ); PS:我所有的頁面都是用Big5 PS:我問過公司很多IT人員,沒有一個會處理這個問題,我不是IT人員,但是因為自己的怨念,結果被我自己一個一個試,被我try出來 PS:為什麼這樣設定就可以顯示中文我實在是不解,我的程度還很淺,希望知道的大大指教 結語: 這樣的設定方式就可以使用Post的方式傳值寫入資料庫,而且都是顯示正確的中文,希望對遇到同樣問題的版眾有所幫助,這個網站的資料真是豐富,如果哪天我看的懂網站只要大約一半的內容,我想我就可以說我是java的高手了 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||
lin0_o 發文: 12 積分: 1 |
收藏文章? ||
[POST 的情況] 加上 Filter 作處理 [GET 的情況] 1. 則在 {tomcat}/conf/server.xml 加上 URIEncoding="UTF-8" 2. 如果用 link 的話, 還要把中文部分先編碼 String str = java.net.URLEncoder.encode("中文","UTF-8"); <a href="/mytest/test.jsp?str=<%=str%>" 這樣會變成還是要每次處理 GET 方式傳遞過來的數值, 所以我請教一下 browser 在這兩篇文章中提到的方式, 在 Filter 裡分 GET / POST 分別作處理, 請問一下是怎樣分的 ?? (這篇討論中 EVAzero 也提出了同樣問題, 我只知道答案不是 request.getMethod(); 後來就沒結果了) Re:[心得分享]Tomcat+MySQL使用UTF-8的經驗談 [Re:saintk] [...略] 2. 一樣使用 Filter .. 不過此時必須要分為 GET / POST 做處理 .. 若為 Get 時,使用 getByte 方式轉碼;若為 Post 時,則使用 request.setCharacterEncoding("utf-8"); [略...] Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] [...略] 不過當初我最後的做法是使用 Filter 的方式 Filter 的做法就是:先判斷是使用那種傳遞方式( GET or POST),假若是用 GET 的方式就採用第一種 code;若使用POST 方式,就採用第二種 code。 [略...] 謝謝 ========== 自言自語分隔線 ========= Re:疑問有關 "Java Server Side 中文解決方案" [Re:javasoth] 將上面這篇文章中的 doFilter 裡面 的 request 轉型就可以用了
lin0_o edited on 2005-05-08 11:17
|
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||
rueitsung 發文: 1 積分: 0 |
收藏文章? ||
之前我也遇上相同的問題,後來發現似乎linux的版本不同也有關係喔! 原本我使用的是Mandrake 10.0+jdk5.0+tomcat5.19+Mysql4.18 只要在每個jsp裡加上
就可正確顯示了。(我的輸入,輸出都統一使用UTF8) 可是後來使用CentOS4.0+jdk5.0+tomcat5.19+Mysql4.18 卻一直有中文亂碼的問題,後來才發現程式中字串一定要做轉碼的工作,才能夠解決中文亂碼的問題。這是我用Mandrake時,沒遇上的。
似乎Mandrake 對中文支援相當不錯,或許有別的原因吧,小弟對linux學藝不精,就當小小心得,與大家分享 |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||
bgyeats 發文: 131 積分: 0 |
收藏文章? ||
看了以上各位的說法 我是覺得還試想統一用 Filter 作掉..這樣就不用在每一頁都要去編碼 在filter裡面 post的部分就是用
但是get的部分是要如何時作ㄋ 很多大大都說是用
但是我還是不了解,因為是要做整個site共用的filter,所以一定會已很多的參數 所以根本不知道參數的名字,而且參數很多不可能每個都寫一遍,再來是又要如何塞回request 不知道有沒有像post那樣簡單一次解決的method可以用 能請有時做出來的大大說明嗎 感謝^^ |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||||||||||
bee 發文: 30 積分: 5 |
收藏文章? ||
爬了兩星期的網頁中文link,終於成功了,分享一下我的設定,希望對各位有用, 因為每人PC環境及設定不盡相同,希望設定成功者,也將您的成功經驗分享給大家. A.我的環境: System:Win2k java:1.5 tomcat:5.5.17, code:UTF-8 Eclipse:3.2.0, project code:UTF-8 B.全部唯一的設定 如 EVAzero 說 修改{tomcat}/conf/server.xml 原部份內容
新增一句"URIEncoding="UTF-8"", 即
B-1.至於其他的以下二項我是沒增修, B-1-1.自己的站台/mytest/WEB-INF/classes/filters/SetCharacterEncodingFilter.class B-1-2.修改mytest/WEB-INF/web.xml 相反的,加入後,IE還會有找不到程式404的錯誤,因為我編輯及編譯 jsp 都是放在 Eclipse 下,非置於 Tomcat webapps下. C.網頁 form link 時, 就要先把中文部分先編碼
D.接收的.jsp, 採用如下
E.舉個範例: DirRead.jsp
DirShow.jsp
祝福各位也能成功! |
作者 | Re:解決 Tomcat 5.0.19 中文參數傳遞問題 [Re:精靈] | ||||||
magus0803 發文: 2 積分: 0 |
收藏文章? ||
最近一段時間經常被亂碼所困擾,今天研究了很久終於明白了各位大大的意思並找出了一個比較簡單的解決方法,希望能對大家有點幫助 TOMCAT5.0開始POST和GET確實傳送參數有改變 一. 如果是通過POST傳遞,其實傳送表單數據是通過REQUEST進行傳遞,如果要得到表單裡傳遞的中文參數,可以通過2個方法 1.
2.
二. 如果是通過GET傳遞,這時傳送表單數據就是通過URI來進行傳遞,這樣無法用request.setCharacterEncoding();來進行設定了,這也就是POST和GET不能用同一方法進行處理,我選擇的方法是將$TOMCAT_HOME/CONF/SERVER.XML中 <Connector>標籤中加入一個屬性URIEncoding="GBK"這樣TOMCAT就會將URI以GBK的編碼方式進行傳遞,我們可以直接通過 String name=request.getParameter("name"); 來得到所要得到的中文的參數. 總結而言,在$TOMCAT_HOME/CONF/SERVER.XML中 <Connector>標籤中加入一個屬性URIEncoding="GBK"並在代碼(比如SERVLET)中以
PS:Request.getMethod()方法返回一個String類型的對象來表示傳遞的方法是POST或是GET |