flex url http后台传递参数方法

flex url http后台传递参数方法

request=new URLRequest("http://localhost:7002/greatSpringCXFWebservice/FileUploaded");
                var variables:URLVariables = new URLVariables();
                var userName = Setting.userInfo.userLoginName; 
                    variables.filedir = Setting.userInfo.userLoginName;
                    request.data=variables;
                     request.method=URLRequestMethod.GET;//为了后台java创建用户自己的图片库
file.upload(req
flex:
file=new FileReference();
                file.addEventListener(Event.SELECT,onFileSelect);
                file.addEventListener(IOErrorEvent.IO_ERROR,onFileIOError);
                file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete);

java:
 protected void processRequest(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        System.out.println("to upload picture !");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        // 保存文件到服务器中

        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(4096);
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(maxPostSize);
        String filedir = request.getParameter("filedir");
        try {
            List fileItems = upload.parseRequest(request);
            Iterator iter = fileItems.iterator();
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                if (!item.isFormField()) {
                    String name = item.getName();
//                    String filedir = item.get();//获取文件名
                    System.out.println(name);
                    try {
                        File file = new File("D:\\a\\"+filedir);//创建分级目录
                        file.mkdir();

                        item.write(new File(uploadPath+filedir+"\\" + name));
                        // SaveFile s = new SaveFile();
                        // s.saveFile(name); "{\"path\": "[ {"name"}]}" 
                        String path = "[path:{"+name+"}]";
                        out.print(path);//用来返回flex的DataEvent.UPLOAD_COMPLETE_DATA请求
                        
                        out.close();

                    } catch (Exception e) {
                        e.printStackTrace();
                        out.print("{\"error\": "+name+"}");
                        out.close();

                    }
                }
            }
        } catch (FileUploadException e) {
            out.print("{\"error\":"+e.getMessage()+"}");
            out.close();
            e.printStackTrace();
            System.out.println(e.getMessage() + "结束");
        }
    }
uest);



java接收

你可能感兴趣的:(flex url http后台传递参数方法)