| Author |
problem uploading .xls file
|
Kirti Chopra
Greenhorn
Joined: Sep 09, 2009
Posts: 1
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
 |
|
|
subject: problem uploading .xls file
|
|
|