help me!

03-06-08 javang
各位好!
在jsp 中用什么方法把中文变成“%B5%CB%D6%BE%C5%A9”,这样的编码方式
比如我需要一个人的姓名,如:邓志农 变为 “%B5%CB%D6%BE%C5%A9,/1E 变为 %2F。我在jsp 中提交中文,在服务器端把中文变为这些编码。
下面是class部分
public void writeData(String pnrno,String pname){
if ( pnrno == null || pnrno.trim().length()==0 )
System.out.println("pnrno is=" +pnrno);
if ( pname == null || pname.trim().length()==0 )
System.out.println("pname is="+pname);

pnrno1 = pnrno; //URLEncoder.encode(pnrno);
pname1 = pname; //URLEncoder.encode(pname);
//System.out.println(pname1);
StringBuffer sb = new StringBuffer() ;
sb.append("pnrno=");
sb.append(pnrno1);
sb.append("&pname=");
sb.append(pname1);
sb.append("&mysubmit=%B2%E9%D1%AF") ;
String strb = sb.toString();
String line = "\n";
String tempStr = "POST http://www.travelsky.com/gb/Trip.jsp HTTP/1.0" + line;
String tempStr1 ="Accept: */*" + line;
String tempStr2 = "Referer: http://www.travelsky.com/gb/page21.htm"+ line;
String tempStr3 = "Accept-Language: zh-cn" + line;
String tempStr4 = "Content-Type: application/x-www-form-urlencoded"+ line;
String tempStr5 = "Proxy-Connection: Keep-Alive";
String tempStr6 = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 1.0.3705)"+ line;
String tempStr7 = "Host: www.travelsky.com"+ line;
String tempStr8 = "Content-Length: "+strb.length() + line;
String tempStr9 = "Pragma: no-cache"+ line;
String tempStr10 = "Proxy-Authorization: Basic ZGZ3OjExMTExMQ=="+ line+ line;
StringBuffer sb2 = new StringBuffer();
sb2.append(tempStr);
sb2.append(tempStr1);
sb2.append(tempStr2);
sb2.append(tempStr3);
sb2.append(tempStr4);
sb2.append(tempStr5);
sb2.append(tempStr6);
sb2.append(tempStr7);
sb2.append(tempStr8);
sb2.append(tempStr9);
sb2.append(tempStr10);
String temp = sb2.toString();
String str = temp + strb;
try{
outStream.writeBytes(str);
readData();
//outStream.close();
//inStream.close();
}catch(Exception e){
e.printStackTrace();
}
}
在页面提交pname(内容为中文),上述方法接收后要变成%BA%CE%D3%C0%BE%C3 ,怎么在页面上调用

banq
2003-06-08 21:25
将中文转为编码,这个工作我没有碰过,一般在设计时,我也会刻意回避这种情况出现,不知其他哪位有这样的经验。

猜你喜欢