隨筆-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 閱讀(1930) 評論(1)  編輯  收藏

          評論:
          # re: FLEX JAVA 上傳文件【轉】[未登錄] 2008-08-17 16:23 |
          怎么全錯?flex2?  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 永城市| 武乡县| 安丘市| 南澳县| 嘉定区| 苍梧县| 广南县| 无棣县| 青浦区| 苏州市| 肥城市| 海盐县| 多伦县| 克拉玛依市| 平潭县| 顺义区| 大渡口区| 南安市| 壤塘县| 嵊州市| 南投市| 万年县| 鄯善县| 龙泉市| 十堰市| 榆社县| 南丰县| 攀枝花市| 英超| 界首市| 十堰市| 大冶市| 全椒县| 武陟县| 沭阳县| 二连浩特市| 荣昌县| 嵊州市| 翼城县| 敦煌市| 泸州市|