0

I've written a small code in my project where a jsp page takes few parameters like name, cost and image file as parameters as input and stores in the Mysql database.When i'm uploading the file and clicking submit, i get file not found exception.

java.io.FileNotFoundException : 0.jpg (No such file or directory)

After hitting submit button

I've tried uploading from multiple locations. It didn't change. I have a query:.Why is the images absolute path not being displayed in exception. Is the issue related to this?

This is the piece of code that takes the input.

<form name="f" action="re_pro_insert.jsp" method="post" onsubmit="return valid()">
.
.
.

    <tr>
      <td align="center"><font color="#333366" size="+1" face="Georgia, Times New Roman, Times, serif"><strong>Product 
                          Image:</strong></font>
      </td>
      <td align="center">
        <input type="file" name="proimage" size="8" id="b" vlaue="jj">
      </td>
    </tr>

This is the part where the file is read to be stored. this is throwing the exception

FileInputStream fis=null;

String a = request.getParameter("comname");

String b = request.getParameter("proname");
String c = request.getParameter("wardate");
String d = request.getParameter("proimage");
String e = request.getParameter("prorate");
String f="";
String g=f+d;

File image=new File(g);

fis=new FileInputStream(image);

Any idea?

I'm running this on Apache Tomcat 7 through eclipse.

Thank you.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Pardha.Saradhi
  • 468
  • 1
  • 10
  • 27
  • 1
    @Jens: Nope. That ain't gonna work when the webserver runs at a physically different machine than the webbrowser. You just need to make sure that the webbrowser sends the file **contents** not the file path. Then, in the webserver just read the file contents. A decent webbrowser doesn't send the full file path along in the metadata. Only a bad webbrowser (e.g. IE) does, but this should be corrected in the webserver's code. See also the duplicate for an elaborate instruction on how to upload files using JSP/Servlet. – BalusC Mar 19 '16 at 21:15
  • @BalusC: Thanks for the info. I didn't knew what to search for. Got my problem solved after referring to that page and a few google searches. – Pardha.Saradhi Mar 20 '16 at 09:38

0 Answers0