how to write uploadphoto in the insert update delete using
struts? write code struts and jsp jdbc
Answer Posted / k.v.s.ravindrareddy
****************In jsp*********************
<form name="fileupload" enctype="multipart/form-data"
method="post"
action="/photos/fileuploadresult">
<tr>
<td >Photo 1</td>
<td ><input type="file" name="uploads[0]" /></td>
</tr>
<tr>
<td >Photo 2</td>
<td ><input type="file" name="uploads[1]" /></td>
</tr>
<tr>
<td>
<input type='submit' name="submit" value="Submit">
</td>
<tr>
</form>
*************** in struts-config.xml*************
<action path="/photos/fileuploadresult"
type="com.uploads.actions.FileUploadAction" name="PhotoUpload"
scope="request" >
<forward name="success" path="/photos/fileuploadresult.jsp" />
</action>
<form-bean name="PhotoUpload"
type="com.uploads.forms.FileUploadForm">
</form-bean>
***************in FileUploadForm.java***************
public class FileUploadForm extends ActionForm {
private List formFiles = new ArrayList();
public List getUploads() { return this.formFiles; }
public void setUploads(int iIndex, FormFile formFile){
this.formFiles.add(formFile);
}
}
***************In execute method of
FileUploadAction.java***************
FileUploadForm uploadForm=(FileUploadForm)form;
List myFiles =(List) uploadForm.getUploads();
for(int i=0;i<myFiles.size();i++){
if(myFiles.get(i)!=null){
FormFile myFile =(FormFile)myFiles.get(i) ;
/*process ur file......*/
}
}
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
Why are frameworks used?
What configuration changes are required to use Tiles in Struts?
How does interceptor work in struts2?
Where should struts xml be placed?
How can we handle exceptions thrown by application in Struts2?
What is structs 2 validation framework?
How many servlet controllers are used in a Struts Application?
What is the difference between Jakarta Struts and Apache Struts? Which one is better to use?
how to connect from struts to database through hibernet and where u can modify the class
What is the use of reset method of ActionForm class?
How action-mapping tag is used for request forwarding in struts configuration file?
For a single Struts application, can we have multiple struts-config.xml files?
What is DynaActionForm?
What is the purpose of plug-in tag in struct-config.xml?
Explain the complete struts validator framework.