Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem uploading .xls file

 
Kirti Chopra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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!!
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic