FLEX JAVA 上传文件

FLEX JAVA 上传文件【转】
用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("");  

你可能感兴趣的:(FLEX JAVA 上传文件)