java flex上传_FLEX JAVA 上传文件【转】

import com.oreilly.servlet.MultipartRequest;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.IOException;

import java.io.PrintWriter;

public class UploadServlet extends HttpServlet {

protected void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {;}

protected void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {

MultipartRequest parts = new MultipartRequest( req, "C:\\MyUploadPath" );

PrintWriter out = res.getWriter();

out.print( "SUCCESS" );

out.close();

}

}

in mxml:

< mx:Application initialize="initApp( event )" xmlns:mx="http://www.macromedia.com/2003/mxml">

< mx:Button id="btnUpload" label="Upload..." click="doUpload( event )" />

< mx:Image id="imgUpload" width="100%" height="100%" horizontalAlign="center" />

as:

private function doUpload( event:Object ):Void {

var file:FileReference = new FileReference();

// Ask the user to choose a file to upload

if( file.browse( ["JPEG Files", "*.jpg"] ) ) {

file.addListener( this );

file.upload( "http://myurl/servlet/MyUploadServlet" );

}

}

private function onUploadSuccess( ref:FileReference, response:String ):Void {

imgUpload.source = "http://myurl/myfilepath/" + ref.name;

}

private function onUploadFailed( ref:FileReference, error:String, response:String ):Void {

mx.controls.Alert.show( "Upload error: " + error );

}

servlet获取绝对路径方法:

ServletConfig   config   =   this.getServletConfig();

ServletContext   context   =   getServletContext();

String   path   =   context.getRealPath("");

posted on 2007-12-03 14:50 Super·shen BLOG 李禄燊 阅读(1875) 评论(1)  编辑  收藏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值