applet向Servlet请求,URL中的中文,在Servlet端变成了乱码!请教高手如何解决?
如题:
代码如下 Applet端!
urlString = servletUrl + "?action= " + action + "&name= " + "中文 ");
URL url = new URL(urlString);//此处打印仍然保持中文
URLConnection urlconnection = url.openConnection();
brd = new BufferedReader(new InputStreamReader urlconnection.getInputStream(), "GBK "));//可以正常接收中文!
Servlet接收!
public void service (HttpServletRequest req, HttpServletResponse res)
throws
ServletException,
IOException {
String name = req.getParameter( "name ");
log( "Name = " + name);//现实为“????”
}
请不吝赐教~谢谢!
------解决方案--------------------urlString = servletUrl + "?action= " + action + "&name= " + java.net.URLEncoder.encode( "中文 ", "UTF-8 ");
servlet:
String name = req.getParameter( "name ");
log( "Name = " + java.net.URLDecoder(name. "utf-8 "));//现实为“????”
------解决方案--------------------如果不行,urlString 中文2次encode,然后servlet端一次decode