首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

url中文编码有关问题

2012-01-14 
url中文编码问题在一个页面上htmlheadmetahttp-equiv Content-Type content text/htmlcharset

url中文编码问题
在一个页面上
<html> <head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=utf-8 "   /> </head>
<body>
<form   method= "get "   action=/webchat/sender.cl>
<input   id= "receiver "   name= "receiver "   type= "text "   />
<input   id= "msg "   name= "msg "   type= "text "/> <
input   type= "submit "/>
</form>
</body> </html>
在msg框打上 "输入 "2词的时候,编码会成%26%2336755%3B%26%2320837%3B
在服务器端接受到是&#36755;&#20837;
而在url中将输入的编码改为:%E8%BE%93%E5%85%A5
服务器端则是正确的显示


[解决办法]
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " /> </head>


这个地方错了,编码方式应该是charset=GBK 或者是GB23
[解决办法]
如果你是用TOMCAT服务器的话:把SERVER.XML文件里的: <Connector port= "80 " maxHttpHeaderSize= "8192 "
maxThreads= "150 " minSpareThreads= "25 " maxSpareThreads= "75 "
enableLookups= "false " redirectPort= "8443 " acceptCount= "100 "
connectionTimeout= "20000 " disableUploadTimeout= "true " URIEncoding= "UTF-8 "/>
URIEncoding= "UTF-8 "/这句写成这样
要不把页面的改为
<%@page language= "java " contentType= "text/html; charset=GBK " pageEncoding= "GBK "%>

[解决办法]
<%
String msg=request.getParameter( "msg ");
name=new String(name.getBytes( "ISO8859_1 "),
"gb2312 ");
out.println( "msg: " +name+ " <br> ");
%>

[解决办法]
action里加request.setCharacterEncoding( "utf-8 ");试试

热点排行