Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/04/2013, 09:25
Avatar de el_java
el_java
 
Fecha de Ingreso: enero-2008
Mensajes: 185
Antigüedad: 16 años, 4 meses
Puntos: 3
Respuesta: Servlet... Problema al Subir Archivo

Hola...

Si, está con method post
y además en multipart/form-data



intenté otro metodo y funcionó... lo colocaré por si alguien lo busca...


Código C:
Ver original
  1. public ActionForward uploadFile2(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  2.        
  3.        
  4.         DynaValidatorForm miFormulario = (DynaValidatorForm) form;
  5.         FormFile fichero = (FormFile) miFormulario.get ("fichero");
  6.         String fileName = fichero.getFileName();
  7.         int fileSize = fichero.getFileSize();
  8.  
  9.        
  10.         if ((fileSize>0)&&(!fileName.equals(""))){
  11.             if(!fileName.equals("")){
  12.                
  13.                
  14.                 java.util.Date fechaUtil = new java.util.Date(); //fecha actual
  15.                 long lnMilisegundos = fechaUtil.getTime();
  16.                 java.sql.Date sqlDate = new java.sql.Date(lnMilisegundos);
  17.                 java.sql.Time sqlTime = new java.sql.Time(lnMilisegundos);
  18.                
  19.                 String fecha = sqlDate.toString();
  20.  
  21.                
  22.                 String dir = "C:\\prueba\\"+fecha;
  23.                
  24.                 File folder = new File(dir);
  25.                 folder.mkdirs();
  26.  
  27.                 File ficheroACrear = new File(dir, fileName);
  28.                 FileOutputStream fileOutStream = new FileOutputStream(ficheroACrear);
  29.                 fileOutStream.write(fichero.getFileData());
  30.                 fileOutStream.flush();
  31.                 fileOutStream.close();
  32.                
  33.                 String file = "C:\\prueba\\"+fecha+fichero;
  34.                
  35.                 Insertardesdexlsx(file);
  36.             }
  37.             return mapping.findForward("upload");
  38.         }else{
  39.             return mapping.findForward("select");
  40.         }
  41.     }


Código C:
Ver original
  1. <html:form action="callCenterFile" method="post" enctype="multipart/form-data">
  2. <html:hidden property="operation" />
  3. <html:hidden property="flagOperation" />
  4. <label>Fichero</label>
  5. <html:file property="fichero"/>
  6. <a href="javascript:search2('uploadFile2')"><html:img src="img/bt_inserir_c_es.gif" border="0" /></a><html:img src="img/1px.gif" width="5" />
  7. </html:form>



Al parecer era problema de struts-config

Código XML:
Ver original
  1. <action path="/callCenterFile" type="br.com.tpi.contract.callCenter.CallCenterAction" parameter="operation" name="CallCenterFile" input="/WEB-INF/jsp/callCenter/callCenter.jsp" scope="request" validate="true">
  2.         <forward name="upload" path="/WEB-INF/jsp/callCenter/uploadFile.jsp"/>
  3.         <forward name="failure" path="/WEB-INF/jsp/errorpage.jsp"/>
  4.         </action>




Aunque igual no se porqué no funciona el otro código...
salu2
__________________
La Mejor banda de Rock Chileno : Los Bunkers