servlet中获取(其他网站的)验证码,显示在自己页面上

        有时候要获取其他网站的代码来实现模拟登陆,下面使用servlet来实现:程序代码如下:


String urlStr = "http://xxx.xxx.xx.xx";
         URL url 
= new URL(urlStr);
         URLConnection conn 
= url.openConnection();
          conn.connect();          
          InputStream is 
= conn.getInputStream();
          
        
//得到输入的编码器,将文件流进行jpg格式编码
            JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is);
         
//得到编码后的图片对象
         BufferedImage image = decoder.decodeAsBufferedImage();
         
//得到输出的编码器
          OutputStream output = response.getOutputStream();
          JPEGImageEncoder encoder 
= JPEGCodec.createJPEGEncoder(output);
          encoder.encode(image);
//对图片进行输出编码
          is.close();//关闭文件流
          output.close();
  比较简单。。。。。hoho

posted on 2009-04-23 20:38 胡鹏 阅读(358) 评论(0)  编辑  收藏 所属分类: java基础J2EE


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

统计

常用链接

留言簿(3)

随笔分类

随笔档案

agile

搜索

最新评论

阅读排行榜

评论排行榜