Hi,
Below are my classes
<%@ taglib uri="/tags/struts-html" prefix="html" %> <html:html> <body> <html:form action="upload" enctype="multipart/form-data"> Select a File :<html:file property="file"/> <html:submit/> </html:form> </body> </html:html>
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
public class UploadForm extends ActionForm{
private FormFile file;
public FormFile getFile(){
return this.file;
}
public void setFile(FormFile file){
this.file=file;
}
}
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.sql.*;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
public class UploadAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
UploadForm uploadForm=(UploadForm)form;
System.out.print("Executed");
FormFile formFile=uploadForm.getFile();
System.out.print("Executed1");
String fileName=formFile.getFileName();
System.out.print(fileName);
File file=new File(fileName);
System.out.print(">>>>");
FileInputStream fin=new FileInputStream(file);
System.out.print("*****");
Integer fileSize=formFile.getFileSize();
int insert=0;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver Loaded.");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
System.out.println("Connection Opened.");
PreparedStatement pst=con.prepareStatement("insert into upload values(?)");
pst.setBinaryStream(1,fin,fileSize);
insert=pst.executeUpdate();
System.out.print("File Uploaded.");
}
catch(Exception e){System.out.println(e);}
if(insert!=0){
return mapping.findForward("success");
}
else{
return mapping.findForward("error");
}
}
}
I am getting error in this line * FileInputStream fin=new FileInputStream(file);* in the above action class i.e UploadAction.java
And below is the error I am getting in tomcat ...
exception
java.io.FileNotFoundException: ZensarCVFormat.doc (The system cannot find the file specified)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.
Please Help me how to resolve this issue... Kindly reply back ASAP...
Thanks in advance...