Companheiros,
ainda estou enfrentando este problema com o FileUpload do Struts 2.
Pior que isso esta me garrando por um tanto de coisa que depende do upload para funcionar.
O interessante é que os campos campos criados na actions so recebem dados se a condição
for retirada do Form da JSP.
Alguem ja está utilizando o FileUpload do Struts 2 poderia me dar um Help!
Agradeço a ajuda desde ja…
Segue o código até o momento.
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="fileupload" extends="principal">
<action name="fileuploadenviar" class="com.struts.FileUploadAction" method="enviar">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="defaultStack"/>
<result name="success">/index.jsp</result>
<result name="fails"> /index.jsp</result>
</action>
</package>
<include file="struts-default.xml"/>
</struts>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="principal" extends="struts-default">
<interceptors>
<interceptor name="hibernate" class="com.struts.HibernateOpenSessionInViewInterceptor"/>
<interceptor-stack name="stackGeral">
<interceptor-ref name="hibernate"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="stackGeral"/>
<global-results>
<result name="login" type="redirect">/monitoramento.jsp</result>
<result name="error" type="redirect">/pages/Erro.jsp</result>
</global-results>
<action name="principal" class="com.struts.GenericAction">
<result name="success">/META-INF/pages/principal.jsp</result>
</action>
</package>
<include file="struts-default.xml"/>
<include file="faleconosco.xml"/>
<include file="fileupload.xml"/>
</struts>
<%@ taglib uri="/struts-tags" prefix="s" %>
<jsp:include page="/layouts/cabecalho.jsp"/>
<table width="70%" height="508" border="0" align="center" cellpadding="0" cellspacing="10">
<tr>
<td height="2" align="center"><img src="img/px1_azul.jpg" width="100%" height="1"></td>
</tr>
<tr>
<td height="410" valign="top" align="center">
<table border="0" cellpadding="2" cellspacing="2" width="391" align="center">
<form action="fileuploadenviar.action" method="post" enctype="multipart/form-data" >
<tr valign="middle">
<td align="right">Descricao:</td>
<td> <input type="text" name="descricao" label="descricao" class="form" ></td>
</tr>
<tr valign="middle">
<td align="right">Arquivo:</td>
<td><input type="file" name="upload" label="File" ></td>
</tr>
<tr valign="middle">
<td align="right"> </td>
<td><input class="button" type="submit" value="Enviar"></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
<jsp:include page="/layouts/rodape.jsp"/>
/*
* FileUploadAction.java
*
* Created on 8 de Dezembro de 2006, 16:13
*
*/
package com.struts;
import java.io.File;
import org.apache.struts2.Action;
public class FileUploadAction implements Action{
private File upload;
private String uploadContentType;
private String uploadFileName;
public String enviar(){
return "success";
}
public String execute() {
String retorno = "fails";
if (upload == null) {
retorno = "success";
}
return retorno;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
}