How do you upload a file from JSP

Showing Answers 1 - 3 of 3 Answers

ramana

  • Aug 25th, 2006
 

 Hi All,

      From Jsp we can upload file like this.............

You have to give input tag like this in jsp 

   <input type="file" name="upload"/>

or

 By using FormFile calss also we can upload file which is available at

 org.apache.struts.upload.FormFile

  Was this answer useful?  Yes

ranjan

  • Sep 15th, 2006
 

<input type="file" name="upload"/>

how this tag is working, so plz provide me complete details.

thanks

  Was this answer useful?  Yes

hari

  • Sep 27th, 2006
 

Hi,

For example, I want to uplad an .CSV file, just go through the following lines, This excerpts are from the struts view.

Your jsp :

<html:form action="/ImportTool.do" enctype="multipart/form-data" onsubmit="return validateFileIfAny()">

Please select the file to upload: <html:file property="CSVFile" value="" name="browseFile" size="20"/>

In our action form bean, declare a property of org.apache.struts.upload.FormFile

private FormFile CSVFile;

/**
  * @return Returns the cSVFile.
  */
 public FormFile getCSVFile() {
  return CSVFile;
 }
 /**
  * @param file The cSVFile to set.
  */
 public void setCSVFile(FormFile file) {
  CSVFile = file;
 }

in u r action class,

protected  ActionForward doPerform(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response){

fileName =  form.getCSVFile();

// do u r own processing .....

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions