Faltava a lib commons-io e faltava  acertar o if no servlet:

*if*(item.isFormField()){  para
*if*(!item.isFormField()){

Se não ele gerava o arquivo como null;


2011/8/4 Re JMD <rjmdf...@gmail.com>

> Pessoal,
>
> Sigo na minha busca por uma solução para realizar uplod com java + flex.
> Achei um exemplo de servlet porém porem o flex está retornando um erro:
>
> Error #2044: IOErrorEvent: não manipulado. text=Error #2038: Erro do
> arquivo de E/S.
>  at com.fozci.sicorc.views::TelaImportarRazao/init()[C:\Documents and
> Settings\...\workspace\Sicorc\flex_src\com\...\sicorc\views\TelaImportarRazao.mxml:16]
>  at
> com.fozci.sicorc.views::TelaImportarRazao/___TelaImportarRazao_Application1_creationComplete()[C:\Documents
> and
> Settings\...\workspace\Sicorc\flex_src\com\...\sicorc\views\TelaImportarRazao.mxml:7]
>  at flash.events::EventDispatcher/dispatchEventFunction()
>  at flash.events::EventDispatcher/dispatchEvent()
>  at
> mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:12528]
>  at mx.core::UIComponent/set
> initialized()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:1627]
>  at
> mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
>  at
> mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
>
> Segue o Servlet e o mxml:
>
> Servlet:
> *
>
> import
> *java.io.IOException;*
>
> import
> *java.util.Iterator;*
>
> import
> *java.util.List;
>
> *
>
> import
> *javax.servlet.ServletException;*
>
> import
> *javax.servlet.http.HttpServlet;*
>
> import
> *javax.servlet.http.HttpServletRequest;*
>
> import
> *javax.servlet.http.HttpServletResponse;
>
> *
>
> import
> *org.apache.commons.fileupload.FileItem;*
>
> import
> *org.apache.commons.fileupload.disk.DiskFileItemFactory;*
>
> import
> *org.apache.commons.fileupload.servlet.ServletFileUpload;
>
>  *
>
> public
> **class* FileUploadServlet *extends* HttpServlet{
>
> *private* String uploadpatch = "/teste/";
>
> *public* *static* *final* *int* *maxPostSize* = 100*1024*1024;
>
> *
>
> public
> *FileUploadServlet (){
>
> *super*();
>
> }
>
> *protected* *void* processRequest(HttpServletRequest request,
> HttpServletResponse response) *throws* Exception{
>
>  *try* {
>
> response.setContentType(
> "text/html;charset=UTF-8");
>
> DiskFileItemFactory factory =
> *new* DiskFileItemFactory();
>
> factory.setSizeThreshold(4096);
>
> ServletFileUpload upload =
> *new* ServletFileUpload(factory);
>
> upload.setFileSizeMax(
> *maxPostSize*);
>
> List<FileItem> fileItens= upload.parseRequest(request);
>
> Iterator<FileItem> iter = fileItens.iterator();
>
> *while* (iter.hasNext()){
>
> FileItem item = iter.next();
>
> *if*(item.isFormField()){
>
> item.write(
> *new* File(uploadpatch + item.getName()));
>
> }
>
> }
>
> }
> *catch* (Exception e) {
>
> *throw* e;
>
> }
>
> *protected* *void* doGet(HttpServletRequest request, HttpServletResponse
> response)
>
> *throws* ServletException, IOException{
>
> *try* {
>
> processRequest(request, response);
>
> }
> *catch* (Exception e) {
>
> e.printStackTrace();
>
> }
>
> }
>
> *protected* *void* doPost(HttpServletRequest request, HttpServletResponse
> response)
>
> *throws* ServletException, IOException{
>
> *try* {
>
> processRequest(request, response);
>
> }
> *catch* (Exception e) {
>
> e.printStackTrace();
>
> }
>
> }
>
> *public* *void* destroy(){
>
> *super*.destroy();
>
> }
>
> }
>
> }
>
>
>
> Segue o mxml:
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <!--
> http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/-->
>
> <mx:Application
> xmlns:mx="http://www.adobe.com/2006/mxml";
>
> layout="
> vertical"
>
> verticalAlign="
> middle"
>
> backgroundColor="
> white"
>
> creationComplete="init();"
> >
>
> <mx:Script>
>
> <![CDATA[
>
> *private* *var* fileRef:FileReference;
>
> *var* request:URLRequest = *new* URLRequest (*"
> http://localhost:8080/Sicorc/FileUploadServlet"*);
>
> *private* *function* init():*void* {
>
> fileRef =
> *new* FileReference();
>
> fileRef.addEventListener(Event.SELECT, fileRef_select);
>
> fileRef.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);
>
> fileRef.addEventListener(Event.COMPLETE, fileRef_complete);
>
> }
>
> *private* *function* browseAndUpload():*void* {
>
> fileRef.browse();
>
> message.text =
> *""*;
>
> }
>
> *private* *function* fileRef_select(evt:Event):*void* {
>
> *try* {
>
> message.text =
> *"size (bytes): "* + numberFormatter.format(fileRef.size);
>
> fileRef.upload(request);
>
> }
> *catch* (err:Error) {
>
> message.text =
> *"ERROR: zero-byte file"*;
>
> }
>
> }
>
> *private* *function* fileRef_progress(evt:ProgressEvent):*void* {
>
> progressBar.visible =
> *true*;
>
> }
>
> *private* *function* fileRef_complete(evt:Event):*void* {
>
> message.text +=
> *" (complete)"*;
>
> progressBar.visible =
> *false*;
>
> }
>
> ]]>
>
> </mx:Script>
>
> <mx:NumberFormatter id="numberFormatter" />
>
> <mx:Button label="Upload file"
>
> click="browseAndUpload();"
> />
>
> <mx:Label id="message" />
>
> <mx:ProgressBar id="progressBar"
>
> indeterminate="
> true"
>
> visible="
> false" />
>
> </mx:Application>
>

-- 
Você recebeu esta mensagem porque está inscrito na lista "flexdev"
Para enviar uma mensagem, envie um e-mail para flexdev@googlegroups.com
Para sair da lista, envie um email em branco para 
flexdev-unsubscr...@googlegroups.com
Mais opções estão disponíveis em http://groups.google.com/group/flexdev

Responder a