Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

problem uploading .xls file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all i am new to struts 2.0 trying to upload a file but getting null in SOP in my action class and 404 error my jsp is like this

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>


<div class="centertb">

<div class="subTitleText" style="padding-left: 50px;">
<s:form method="POST" enctype="multipart/form-data" theme="simple">
<table width="80%" style="font-weight: normal;">
<tr>
<td>
<s:file name="file" label="File"></s:file>
</td>
</tr>
<tr>
<td><s:submit action="uploadXls"cssClass="submitButton" label="upload xls" align="left" cssStyle="margin-left:100px;"/></td>
</tr>
</table>
</s:form>
</div>
</div>


action class i am trying this:


import java.io.File;
import java.lang.Object;
import org.apache.commons.io.FileUtils;
import com.sun.deploy.cache.Cache;


/**
* Created by IntelliJ IDEA.
* User: Owner
* Date: Sep 9, 2009
* Time: 10:22:18 AM
* To change this template use File | Settings | File Templates.
*/
public class UploadXlsAction extends BaseAction {
private File file;
private String uploadContent;
private String fileName;
private UploadXlsAction upload;
public String execute() throws Exception
{
this.file=getFile();
this.fileName=getFileName();
String filepath=file.getAbsolutePath();
upload.uploaded(file,fileName,filepath);
System.out.println(filepath);
System.out.println(fileName);

return "success";
}
public File getFile() {
return file;
}

public void setFile(File file) {
this.file = file;
}

public String getUploadContent() {
return uploadContent;
}

public void setUploadContent(String uploadContent) {
this.uploadContent = uploadContent;
}

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
System.out.println(fileName);
}

public void uploaded(File file, String fileName, String directoryName){
File dir = new File(directoryName);
if (!dir.exists()) {
dir.mkdir();
}
String targetPath = dir.getPath() + File.separator + fileName;
File fileDestination = new File(targetPath);
FileUtils.copyFile(file, fileDestination);

}

}

Please help

Thanks!!
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kirti, welcome to javaranch.

Kirti please Use Code Tags when you post a source code. Edit your message using button and then add code tags to it.

Also can you confirm that the interceptor stack that you are using for this action has the file-upload-interceptor in it...
 
reply
    Bookmark Topic Watch Topic
  • New Topic