Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File Not Found Exception when uploading  RSS feed

 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day!

I have a code that should upload files. I tested 2 scenarios:

1st:
Upload multiple files from the Client to Server and save it in a folder in the Server's file system.
RESULT: Successful

2nd:
Upload multiple files from the Client to Server and save it in the database
RESULT: File Not Found Exception

Here's a piece of the code:
process.jsp


httpmultifile.java



Stack trace:

java.io.FileNotFoundException: C:\Documents and Settings\cimuser\My Documents\Dada\FileReader\WebRoot\Raw\325654654.txt (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.jsp.HttpProcessDB_jsp._jspService(HttpProcessDB_jsp.java:118)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)
java.io.FileNotFoundException: C:\Documents and Settings\cimuser\My Documents\Dada\FileReader\WebRoot\Raw\325654654.txt (The system cannot find the path specified)

Hoping for your replies.
Thanks.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you attempting to open the uploaded file on the server, but I don't see you actually saving the uploaded file on the server.
Also, in this line:

You are setting the size of the incoming data to the length of the file name.
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I see, in that case what method should I use?
Am I doing a feasible thing or is in the right track? I mean, based from the JSP FAQ in this forum, I found the tutorial for HttpClient based FileUpload. I used it and combined it with my codes. Can it really upload files to the database?

Thanks.
[ September 04, 2007: Message edited by: Darren Alexandria ]
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I see, in that case what method should I use?

To do what? Find the size of the uploaded item? Have a look at the FileItem documentation and it will jump out at you.

Am I doing a feasible thing or is in the right track?


Sure. You're just missing the step where you save the uploaded file to where your FileInputStream is looking for it.
Not to confuse things, but you could have the prepared statement read directly from the file item and eliminate the temporary file. Either way will work.
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quote:Ah I see, in that case what method should I use?



To do what? Find the size of the uploaded item? Have a look at the FileItem documentation and it will jump out at you.



I am finding a way on how to save the file to the database. I already have a code for saving files in the Server's file system.

Yey! At least I know I am on the right track and what I am doing is feasible. Thanks so much. I will try your suggestion and try to make something right out of it. If ever I will encounter another problem (which I'm sure I'll have), I will post it here again and I hope that you will still give me advice by then.

Thank you so much.
God bless.

Darren
[ September 05, 2007: Message edited by: Darren Alexandria ]
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed some part of the code by it still gets the same results (FILE NOT FOUND):

I am using Apache Commons File Upload and HttpClient. Thanks.



Stack Trace:


java.io.FileNotFoundException: C:\Documents and Settings\Administrator\Desktop\test.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.jsp.HttpProcessDB_jsp._jspService(HttpProcessDB_jsp.java:139)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)
java.io.FileNotFoundException: C:\Documents and Settings\Administrator\Desktop\test.txt (The system cannot find the file specified)
[ September 06, 2007: Message edited by: Darren Alexandria ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!