...

View Full Version : Problem with uploading images using Jsp



swethak
12-10-2008, 07:58 AM
Hi,


My Requirement is to upload the images into database through jsp. For that i write a code .And it works fine .But in that File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg"); instead of that i used File imgfile = new File("Blue.jpg"); like that it didn't work. When we browse that image from local system it automatically takes like Blue.jpg and didn't take the full path.
So i got the error as " Blue.jpg not found". Please tell the solution how can i resolve my problem.





<%@ page import="java.sql.*" %>
<%@ page import="java.io.*"%>
<%
String connectionURL = "jdbc:mysql://localhost:3306/";
String dbName = "user_register";
Connection connection = null;
PreparedStatement pre=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL+dbName, "root", "root");
out.println("connection");
File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg");
out.println("reerr");
FileInputStream fin = new FileInputStream(imgfile);
pre = connection.prepareStatement("insert into Image values(?,?,?)");
pre.setInt(1,3);
pre.setString(2,"new");
pre.setBinaryStream(3,fin,(int)imgfile.length());
pre.executeUpdate();
out.println("Inserting Successfully!");
%>

lokeshshettyk
12-10-2008, 08:05 AM
You need to be a little more clear about your problem, would be tough to deal with otherwise.

In your code, you have used

File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg");

Did you mean that you were trying to use

File imgfile = new File("Blue.jpg");
and it did not work?

swethak
12-10-2008, 03:17 PM
hi,

yes exactly i trying like that .plz tell the solution for that

lokeshshettyk
12-10-2008, 04:49 PM
File imgfile = new File("Blue.jpg"); - this would work only if the image is stored directly under the root folder (something like /usr/local/apache/htdocs/blue.jpg).
say for ex: if your root folder is C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/ and assume that the image is stored under a folder named 'images' then the path should be File imgfile = new File("/images/blue.gif"); else your program will not find the file specified.

Hope this helps


Cheers :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum