You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by KIRTI CHOPRA <ki...@gmail.com> on 2009/09/10 06:50:29 UTC
uploading a .xls file
hi all
i am new to struts and trying to upload a file in struts 2.0
i am using <s:file> tag and have given simple getter setters in action class
i am getting null value in file name pls help and let me know how i can do
it.
code is given below:
Action class
package com.neevtech.newsletter.action;
import java.io.File;
/**
* 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;
public String execute() throws Exception
{
this.file=getFile();
this.fileName=getFileName();
/*String filepath=file.getAbsolutePath();
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 String uploaded(){
this.file=getFile();
this.fileName=getFileName();
System.out.println(fileName);
return "success";
}
}
Jsp page
<%@ 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>
--
View this message in context: http://www.nabble.com/uploading-a-.xls-file-tp25377242p25377242.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: uploading a .xls file
Posted by KIRTI CHOPRA <ki...@gmail.com>.
Thank you so much for the help!!!
--
View this message in context: http://www.nabble.com/uploading-a-.xls-file-tp25377242p25383919.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: uploading a .xls file
Posted by Bill Bohnenberger <bi...@gmail.com>.
Write code in your action class to copy the temp file. You'll have to
respect your application server's containment rules: I simply copy the file
to a permanent place in my application context.
On Thu, Sep 10, 2009 at 12:59 AM, KIRTI CHOPRA <ki...@gmail.com>wrote:
>
> Thank you so much but can you please tell me how can i save the uploaded
> file
> --
> View this message in context:
> http://www.nabble.com/uploading-a-.xls-file-tp25377242p25378975.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: uploading a .xls file
Posted by KIRTI CHOPRA <ki...@gmail.com>.
Thank you so much but can you please tell me how can i save the uploaded
file
--
View this message in context: http://www.nabble.com/uploading-a-.xls-file-tp25377242p25378975.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: uploading a .xls file
Posted by Bill Bohnenberger <bi...@gmail.com>.
if you use name="file" in the <s:file> tag, your variable names should be
"file", "fileFileName" and "fileContentType"
- Bill
On Wed, Sep 9, 2009 at 10:45 PM, KIRTI CHOPRA <ki...@gmail.com>wrote:
>
> hi
> but does it make any difference it is just variable name if i am not wrong
> but i am not sure about it also
> please let me know if it makes any difference.
>
> Thanks!!!
> --
> View this message in context:
> http://www.nabble.com/uploading-a-.xls-file-tp25377242p25377629.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: uploading a .xls file
Posted by KIRTI CHOPRA <ki...@gmail.com>.
hi
but does it make any difference it is just variable name if i am not wrong
but i am not sure about it also
please let me know if it makes any difference.
Thanks!!!
--
View this message in context: http://www.nabble.com/uploading-a-.xls-file-tp25377242p25377629.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: uploading a .xls file
Posted by Steven Yang <ke...@gmail.com>.
are u getting anything from the uploadContent?
because i think i should be
File file
String fileContentType
String fileFileName
On Thu, Sep 10, 2009 at 12:50 PM, KIRTI CHOPRA <ki...@gmail.com>wrote:
>
> hi all
> i am new to struts and trying to upload a file in struts 2.0
> i am using <s:file> tag and have given simple getter setters in action
> class
> i am getting null value in file name pls help and let me know how i can do
> it.
> code is given below:
> Action class
>
> package com.neevtech.newsletter.action;
>
> import java.io.File;
>
> /**
> * 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;
>
> public String execute() throws Exception
> {
> this.file=getFile();
> this.fileName=getFileName();
> /*String filepath=file.getAbsolutePath();
> 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 String uploaded(){
> this.file=getFile();
> this.fileName=getFileName();
> System.out.println(fileName);
> return "success";
> }
>
> }
> Jsp page
>
> <%@ 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>
>
> --
> View this message in context:
> http://www.nabble.com/uploading-a-.xls-file-tp25377242p25377242.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>