Bom Dia!
Estou tentando fazer upload com struts, peguei este no http://www.roseindia.net/struts/strutsfileupload.shtml. Sigo os passos do exemplo, mas dá o erro abaixo:
ERROR [[action]] Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at Upload.StrutsUploadAction.execute(StrutsUploadAction.java:28)
de acordo com o exemplo:
No action:
public class StrutsUploadAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
StrutsUploadForm myForm = (StrutsUploadForm)form;
// Process the FormFile
FormFile myFile = myForm.getTheFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName);
System.out.println("File Size: " + fileSize);
return mapping.findForward("sucesso");
}
esse myFile tá vindo nulo, como que pega isso no formulário lá da jsp?
o form:
public class StrutsUploadForm extends ActionForm
{
private FormFile theFile;
public FormFile getTheFile() {
return theFile;
}
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}
Struts:
<form-bean name="FileUpload" type="Upload.StrutsUploadForm"/>
<action
path="/FileUpload" parameter="execute"
type="Upload.StrutsUploadAction"
name="FileUpload"
scope="request"
validate="true"
input="/WEB-INF/web/jsp/upload/fileUpload.jsp">
<forward name="sucesso" path="/WEB-INF/web/jsp/secretaria/home.jsp"/>
</action>
jsp:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:form action="/FileUpload" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Please Enter the Following Details</td>
</tr>
<td>File Name</td>
<td><input type="file" name="theFile"></td>
</tr>
<tr>
<td><html:submit>Upload File</html:submit></td>
</tr>
</table>
</html:form>
Se alguém aí puder ajudar!
Grata