隨筆-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?  回復  更多評論
            

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


          網站導航:
           
          主站蜘蛛池模板: 射阳县| 汝州市| 颍上县| 吴川市| 云阳县| 伊金霍洛旗| 南平市| 泸州市| 略阳县| 镇宁| 财经| 葵青区| 疏附县| 张掖市| 班玛县| 聂荣县| 灵武市| 平武县| 信丰县| 刚察县| 资溪县| 曲沃县| 花莲县| 古田县| 汉中市| 将乐县| 林芝县| 营口市| 隆回县| 襄垣县| 安福县| 山阳县| 手机| 樟树市| 安丘市| 保靖县| 通城县| 黄龙县| 永平县| 巴楚县| 南漳县|