随笔-40  评论-66  文章-0  trackbacks-0
用Flex/Central/Java上传文件      
     in 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" />
</mx:Application>

     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 阅读(1921) 评论(1)  编辑  收藏

评论:
# re: FLEX JAVA 上传文件【转】[未登录] 2008-08-17 16:23 |
怎么全错?flex2?  回复  更多评论
  

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


网站导航: