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接收

posted on 2012-09-12 14:16 youngturk 阅读(972) 评论(0)  编辑  收藏 所属分类: Java基础Flex DEVservlet


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


网站导航:
 
<2012年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

导航

统计

公告

this year :
1 jQuery
2 freemarker
3 框架结构
4 口语英语

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

EJB学习

Flex学习

learn English

oracle

spring MVC web service

SQL

Struts

生活保健

解析文件

搜索

最新评论

阅读排行榜

评论排行榜