html:file - uploading photo files from jsp into a directory
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi Guys,
I'm fairly new to struts, so I'm really struggling!!
I need to do the following:
1) read photos from my jsp page
2) save the folder into a folder.
Here's the code I have so far, but I'm stuck:
<<<JSP>>>>>
<body>
<html:form action="/FileUpload" type="org.apache.struts.validator.DynaValidatorForm" enctype="multipart/form-data">
<table>
<tr>
<td align="center" colspan="2">
<font size="4">ADD Pictures Here</font>
</tr>
<tr>
<td align="right">
File Name
</td>
<td>
<html:file property="sourceFile"/>
</td>
<td>
<html:submit>Upload File</html:submit>
</td>
</tr>
</table>
<<<struts-config>>>
<form-bean name="FileUploadForm" type="org.apache.struts.validator.DynaValidatorForm">
<!-- Dynamic properties of the FileUpload Form -->
<form-property name="sourceFile" type="org.apache.struts.upload.FormFile" />
</form-bean>
<action path="/FileUpload" type="com.poshWebApp.action.FileUploadProcessAction" name="FileUploadForm" scope="request" validate="false" >
<forward name="success" path="/web/service/uploadsuccess.jsp"/>
</action>
<<<action class>>>
public class FileUploadProcessAction extends Action {
public ActionForward execute(ActionMapping mapping_,
ActionForm form_, HttpServletRequest request_,
HttpServletResponse response_) throws Exception {
String status = null;
System.out.println("#####Action: entering search detail action class...");
DynaValidatorForm form = (DynaValidatorForm) form_;
FormFile sourceFile = (FormFile) form.get("sourceFile");
String contentType = sourceFile.getContentType();
String fileName = sourceFile.getFileName();
int fileSize = sourceFile.getFileSize();
byte[] fileData = sourceFile.getFileData();
///???
1. how can I save into a folder here???
///???
status = "session";
return mapping_.findForward(status);
}
}
PleaSe hELp!!!
I'm fairly new to struts, so I'm really struggling!!
I need to do the following:
1) read photos from my jsp page
2) save the folder into a folder.
Here's the code I have so far, but I'm stuck:
<<<JSP>>>>>
<body>
<html:form action="/FileUpload" type="org.apache.struts.validator.DynaValidatorForm" enctype="multipart/form-data">
<table>
<tr>
<td align="center" colspan="2">
<font size="4">ADD Pictures Here</font>
</tr>
<tr>
<td align="right">
File Name
</td>
<td>
<html:file property="sourceFile"/>
</td>
<td>
<html:submit>Upload File</html:submit>
</td>
</tr>
</table>
<<<struts-config>>>
<form-bean name="FileUploadForm" type="org.apache.struts.validator.DynaValidatorForm">
<!-- Dynamic properties of the FileUpload Form -->
<form-property name="sourceFile" type="org.apache.struts.upload.FormFile" />
</form-bean>
<action path="/FileUpload" type="com.poshWebApp.action.FileUploadProcessAction" name="FileUploadForm" scope="request" validate="false" >
<forward name="success" path="/web/service/uploadsuccess.jsp"/>
</action>
<<<action class>>>
public class FileUploadProcessAction extends Action {
public ActionForward execute(ActionMapping mapping_,
ActionForm form_, HttpServletRequest request_,
HttpServletResponse response_) throws Exception {
String status = null;
System.out.println("#####Action: entering search detail action class...");
DynaValidatorForm form = (DynaValidatorForm) form_;
FormFile sourceFile = (FormFile) form.get("sourceFile");
String contentType = sourceFile.getContentType();
String fileName = sourceFile.getFileName();
int fileSize = sourceFile.getFileSize();
byte[] fileData = sourceFile.getFileData();
///???
1. how can I save into a folder here???
///???
status = "session";
return mapping_.findForward(status);
}
}
PleaSe hELp!!!

posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'd be more interested in FormFile's getInputStream() method than the getData() method. Once you have an Input Stream, writing to an output file is just standard Java using the java.io package.
I'd suggest you check out Java Developer's Almanac Site for some example code on how to write to files using the java.io package. Pay particular attention to the "copy One File to Another" example. Even though you're not copying from one file to another, you are copying from an input stream to an output stream.
I'd suggest you check out Java Developer's Almanac Site for some example code on how to write to files using the java.io package. Pay particular attention to the "copy One File to Another" example. Even though you're not copying from one file to another, you are copying from an input stream to an output stream.
Merrill
Consultant, Sima Solutions
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi
try this....
milan.
try this....
milan.
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi Merrill,
Though i have used in a situation, but the particular situation wont DownloadAction (http://www.coresw.com/tsdocs/tsdev101/devedition/javadocs/com/cst/terrasoar/struts/actions/DownloadAction.html) and UploadAction(http://struts.apache.org/1.x/struts-apps/struts-examples/apidocs/org/apache/struts/webapp/upload/UploadAction.html) be useful without bothering for much of the code?
Though i have used in a situation, but the particular situation wont DownloadAction (http://www.coresw.com/tsdocs/tsdev101/devedition/javadocs/com/cst/terrasoar/struts/actions/DownloadAction.html) and UploadAction(http://struts.apache.org/1.x/struts-apps/struts-examples/apidocs/org/apache/struts/webapp/upload/UploadAction.html) be useful without bothering for much of the code?
Regards,<br />Roshani
Merrill Higginson
Ranch Hand
Posts: 4864
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Roshani,
DownloadAction is for downloads only. Not very useful for an upload. The second link refers to a class that was created specifically for use in the example application. It's useful as an example, but not for much more than that.
Since there are so many different things you can do with an uploaded file (save to disk, save as BLOB, save as CLOB, turn into a PDF, etc.) there isn't really a single class that is going to cover all the bases. You pretty much have to crank out the class and do the low level work.
DownloadAction is for downloads only. Not very useful for an upload. The second link refers to a class that was created specifically for use in the example application. It's useful as an example, but not for much more than that.
Since there are so many different things you can do with an uploaded file (save to disk, save as BLOB, save as CLOB, turn into a PDF, etc.) there isn't really a single class that is going to cover all the bases. You pretty much have to crank out the class and do the low level work.
Merrill
Consultant, Sima Solutions
RoshaniG Gopal
Ranch Hand
Posts: 180
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks Merrill !!
Regards,<br />Roshani
Nina Anderson
Ranch Hand
Posts: 148
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
ThAnks guys!! I'm able to now upload the image files, create & delete files
I really appreciate your assistance!
I really appreciate your assistance!
| I wasn't selected to go to mars. This tiny ad got in ahead of me: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |









