Hi Sunny,
It creates a file in "C:\Documents and Settings\uma.k\Start
Menu\Programs\Apache Tomcat 4.0" and its path is virtual and maps to
D:\tomc.... only. But I wanted to upload to "images" directory where my app
is running. e.g. "D:\Program Files\Apache Tomcat
4.0\webapps\test\upload\images"

Here my context is "test" and my jsps are located in "upload" directory. Any
ideas?

Uma

-----Original Message-----
From: Sunny [mailto:[EMAIL PROTECTED]
Sent: Monday, December 20, 2004 12:21 PM
To: Struts Users Mailing List
Subject: Re: file upload problem



JSP:
<%@ taglib uri = "/WEB-INF/struts-html.tld" prefix = "html"%>
<%@ taglib uri = "/WEB-INF/struts-bean.tld" prefix = "bean"%>
<%@ taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic"%>

<html:html xhtml = "true">
<html:form action = "uploadFile" enctype = "multipart/form-data" >
<html:file property = "file2Upload" />
<html:submit>Upload</html:submit>
</html:form>
</html:html>
=========================
struts-config.xml:

<form-bean name = "FileUploadForm" *type=
"org.apache.struts.validator.DynaValidatorForm" *>
<form-property name="file2Upload" type="org.apache.struts.upload.FormFile"/>
</form-bean>

....

<action path = "/uploadFile" name = "FileUploadForm"
type = "mypackage.UploadAction"
input = "/mywebapp/uploadFile.jsp"
scope = "request"
validate = "false">
<forward name = "success" path = "/mywebapp/uploadFile.jsp"/>
</action>

==========================
Action: (execute(..) method)

DynaValidatorForm uploadForm = (DynaValidatorForm)form;
FormFile uploadedFile= (FormFile)uploadForm.get("file2Upload");
byte[] fileData = uploadedFile.getFileData();
String fileName = uploadedFile.getFileName();

//NOW YOU have to write code to create a File object and write to it.

try {
File serverFile = new File(fileName); // Here you should specify the path
serverFile.createNewFile();
FileOutputStream os = new FileOutputStream(serverFile);
os.write(fileData);
os.close();
}
catch(Exception ex) {
System.out.println("ERROR::::::: " + ex);
}


============================














uma.k wrote:

>NO, this might not be best solution as the folders are already existing and
>If I have to move from one OS to another OS then this would be a problem.
>So, I wanted to upload the file to relative path rather than absolute path.
>
>Any one please?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to