Hi ,
I am new to
struts and J2EE.I was trying my first Struts application.I
got the error
java.io.FileNotFoundException: C:\Tomcat 5.0\webapps\IOTDE\upload\new.txt (The system cannot find the path specified)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(Unknown Source)
java.io.FileOutputStream.<init>(Unknown Source)
com.iotde.struts.action.Epcc8Action.execute(Epcc8Action.java:60)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
I am not able to resolve it.
I am using struts 1.1/Tomcat 5.0.16/JDK 1.5
please find bellow is my file upload code. From.java */
public class Epcc8Form extends ActionForm {
/*
* Generated Methods
*/
private FormFile theFile;
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
public FormFile getTheFile() {
return theFile;
}
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}
}
Action.java public class Epcc8Action extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
Epcc8Form epcc8Form = (Epcc8Form) form;// TODO Auto-generated method stub
// Process the FormFile
FormFile myFile = epcc8Form.getTheFile();
String contentType = myFile.getContentType();
//Get the file name
String fileName = myFile.getFileName();
//int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
//Get the servers upload directory real path name
String filePath = getServlet().getServletContext().getRealPath("/") +"upload";
/* Save file on the server */
if(!fileName.equals("")){
System.out.println("Server path:" +filePath);
//Create file
File fileToCreate = new File(filePath, fileName);
//If file does not exists create file
if(!fileToCreate.exists()){
FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
fileOutStream.write(myFile.getFileData());
fileOutStream.flush();
fileOutStream.close();
}
}
//Set file name to the request object
request.setAttribute("fileName",fileName);
return mapping.findForward("complete");
}
}