java编写Web Service,含大文件上传例子

参考文献:http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/bu_tutorial.html

这篇文章写的非常齐全,唯一在问题出在启动服务器后找不到网页,正确的网址应该是

http://localhost:8080/Axis2WSTest/axis2-web

java编写Web Service代码,含文件大文件上传例子

下载:http://code.google.com/p/minioa/downloads/detail?name=Axis2WSTest.zip&can=2&q=

基本步骤:

1、首先创建一个Web项目

2、添加axis视图

3、创建一个java类

4、选择这个java,然后New 创建一个web service,按照向导配置

5、run as ......

上传单个文件代码,值得注意的是当上传文件超过5M时就提示java.lang.outmemoryerror,需要就要考虑分割上传文件,到服务器端再合并

public void uploadImage(String filename, byte[] file) {
	try {
		FileOutputStream fos = null;
		fos = new FileOutputStream(filename);   
		fos.write(file);
		fos.close();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}


合并文件

public int buildFile(String fileName,int num) {
	try{
		int i = 0;
		FileOutputStream fos = null;
		fos = new FileOutputStream(fileName); 
		while(num >=0){
			BufferedInputStream bufferedInputStream=new BufferedInputStream(new FileInputStream(fileName + i));
			byte[] bytes = new byte[(int)(new java.io.File(fileName + i)).length()];
			bufferedInputStream.read(bytes);
			bufferedInputStream.close();
			fos.write(bytes);
			num--;
			i++;
		}
		fos.close();
		//删除文件
		while(i >=0){
			java.io.File f= new java.io.File(fileName + i);
			f.delete();
			i--;
		}
		return 1;
	}catch(Exception ex){ex.printStackTrace();}
	return -1;
}

客户端是用.net winform写的



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值