浏览 3175 次
锁定老帖子 主题:在解决AJAX跨域问题时碰到了乱码
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-05-04
servlet 中的代码如下: public class WmsProxy extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String strUrl = ""; Enumeration param = request.getParameterNames(); while(param.hasMoreElements()){ String pname = param.nextElement().toString(); if(!pname.equalsIgnoreCase("pageNo") ){ strUrl += pname+"="+request.getParameter(pname)+"&"; } } if(strUrl.endsWith("&")){ strUrl = strUrl.substring(0,strUrl.lastIndexOf("&")); } response.setContentType("text/xml"); ServletOutputStream outputStream = response.getOutputStream(); URL url = new URL("http://127.0.0.1:8989/WMSEgi.egi?" + strUrl); InputStream in = url.openStream() ; BufferedReader dr = new BufferedReader(new InputStreamReader(in)); String line; while ((line = dr.readLine())!=null) { System.out.println(line) ; outputStream.print(line); } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-05-05
问题已解决:
response.setContentType("text/xml;charset=utf-8"); ServletOutputStream outputStream = response.getOutputStream(); URL url = new URL("http://127.0.0.1:8989/WMSEgi.egi?" + strUrl); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),"UTF-8")); |
|
返回顶楼 | |