| 发表于:2007-01-29 13:11:313楼 得分:0 |
本来我发现的方法是这样的:winxp pro简体中文版+jdk1.5+eclipse3.2+tomcat5.5.20 使用utf-8的方法: 1:使用eclipse的时候,菜单project-> info-> "text file encoding "-> utf-8 这样可以保证工程所有字符的编码都是utf-8,包括html代码里面的中文。 2:安装数据库的时候选择默认语言utf-8,或着创建表的时候指定语言为utf-8,这样保证数据库存储和处理是utf-8 3:写一个过滤器,url-maping设置为/* ,在dofilter里写两句话就可以了 arg0.setcharacterencoding( "utf-8 "); arg2.dofilter(arg0, arg1); 但是最近我的方法不灵光了,事发是在大约两个星期前,可能因为台湾光纤的问题,eclipse建一个web project要好久,而且好像sun的dtd也出了问题,所以我正在进行的项目换了用netbean,在netbean中开发了一星期都没什么乱码问题,但是一发布到应用服务器上(win2003中文版,tomcat5.5.20,jdk1.5)就发现不行,从网页提交的全是乱码. 测试环境:winxppro 简体中文版+jdk1.5 +eclipse+tomcat 5.5.20 页面源代码是是utf-8编码保存的,方法是在eclipse中edit-> set encoding设置为utf-8. 以下两个页面的代码是把一个中文字传到b页面后不加处理直接回显,但是会出乱码。无论是在eclipse里或着是直接把代码放到tomcate根目录下,都是乱码,请问有人知道原因吗? 但是在netbean5.0里使用它自带的tomcat5.5.17,并设置编译参数为-encoding utf-8,就没有这个问题, 我不希望在项目中使用gbk之类的编码,请大家指教 -----------------a.jsp----------------------------------------------------- [code] <%@ page language= "java " contenttype= "text/html; charset=utf-8 " pageencoding= "utf-8 "%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en " "http://www.w3.org/tr/html4/loose.dtd "> <%request.setcharacterencoding( "utf-8 "); %> <html> <head> <meta http-equiv= "content-type " content= "utf-8 "> <title> insert title here </title> </head> <body> <form action= "b.jsp "> <table> <tr> <td> <input type= "text " name= "name " value= "我 "> </td> <td> <input type= "submit "> </td> </tr> </table> </form> </body> </html> [/code] ----------------------------------------b.jsp--------------------------------------------- [code] <%@ page language= "java " contenttype= "text/html; charset=utf-8 " pageencoding= "utf-8 "%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en " "http://www.w3.org/tr/html4/loose.dtd "> <%request.setcharacterencoding( "utf-8 "); %> <html> <head> <meta http-equiv= "content-type " content= "text/html; charset=utf-8 "> <title> insert title here </title> </head> <body> <%=request.getparameter( "name ") %> </body> </html> [/code] | | |
|