myeclipse jaxws框架写 webservice 之上传图片方法

Jaxws 上传图片方法

        获取图片名字 存至服务器

     获取图片存至 服务器指定磁盘

 这里定义三个参数 一个是图片名称(String 类型),用来存至服务器。二String类型的image

用在存取 经过Base64编码之后的的字节流。 参数三 是我数据库中得一个字段 用来确定 更新用户的行

 

 

下面是

Web服务器完整代码

我已经写好了服务器连接类

package cn.edu.bzu.operate;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.sql.SQLException;

 

import cn.edu.bzu.sqlconnection.sqlDatabaseConnection;

 

import sun.misc.BASE64Decoder;

 

public class userImageUpload extends sqlDatabaseConnection {

    /**

     * @authorxs

     * @param imaName

     * @param image

     * @param Ptel

     * @return boolean

     */

   

    public boolean UpdateImage(String imaName,String image,String Ptel)

    {

       boolean SUCEESS=false;

       int iResult=0;

       FileOutputStream fos=null;

       try {

           getConnection();

           StringsqlInsertUser="update personInfo set Pimage=? wherePtel=? ";

           pStmt=conn.prepareStatement(sqlInsertUser);

           pStmt.setString(1, imaName+".jpg");

           pStmt.setString(2, Ptel);

           iResult=pStmt.executeUpdate();

           if(iResult>0)

           {

              byte[] buffer =newBASE64Decoder().decodeBuffer(image);

              //System.out.println(buffer.length);

                fos = new FileOutputStream("d:\\"+imaName+".jpg");

              fos.write(buffer);

              fos.close();

              SUCEESS=true;

           }

           else{

               SUCEESS=false;

           }

           }catch (SQLException e) {

              e.printStackTrace();

           } catch (FileNotFoundException e) {

              e.printStackTrace();

           } catch (IOException e) {

              e.printStackTrace();

            }finally{

         closeAll();

        try{

              fos.flush();

              fos.close();

        }catch(IOException e){

            e.printStackTrace();

        }

        }

       return SUCEESS;

   

    }

   

 

经过发布之后 

测试代码

Client

package cn.edu.bzu.upimage;

import java.io.*;

 

import com.sun.org.apache.xml.internal.security.utils.Base64;

public class testupImage {

    public static void main(String[] args)throws IOException {

       UserImageUploadDelegate service = newUserImageUploadService().getUserImageUploadPort();

       FileInputStream fis =new FileInputStream("F:\\success.jpg");

       try {

          

           ByteArrayOutputStream baos=new ByteArrayOutputStream();

           byte[] buffer=newbyte[8192];

           int count =0;

           while((count =fis.read(buffer))>=0)

           {

              baos.write(buffer,0,count);

           }

           String uploadBuffer=new String(Base64.encode(baos.toByteArray()));

           boolean Res=service.updateImage("success", uploadBuffer,"18899998765");

           if(Res==true){

              System.out.println("图片已经成功存到服务器");

           }

           else{

              System.out.println("更新头像失败");

           }

       } catch (FileNotFoundException e) {

           // TODO Auto-generatedcatch block

           e.printStackTrace();

       }finally{

           fis.close(); 

       }

      

    }

   

 

}

 

 

完成

 

以上是综合网上代码写

参考地址http://www.doc88.com/p-779458081779.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值