shrutishrma sharma

Greenhorn
+ Follow
since Oct 29, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by shrutishrma sharma

hey i have a problem in obtaining the path of the image which i have to upload using jsp servlet...
actually the problem is ...i have used getParameter to get the image path and then using the image i store the image in database ...but getParameter is not returning me the complete path of the image instead it returns only the image name...
here is my code please check it as soon as possible ....eagerly wating for reply:
my index.jsp page
--------------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<FORM ACTION="upload" METHOD=POST>
<br><br><br>
<center><table border="2" >
<tr>
<center>
<td colspan="2"><p align="center">
<B>UPLOAD THE FILE</B>
</td>
</center>
</tr>
<tr>
<td>
<b>Choose the file To Upload:</b>
</td>
<td>
<input type="file" name="file" value="" />
</td>
</tr>
<tr>
<td colspan="2">
<p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p>
</td>
</tr>
</table>
</center>
</FORM>
</body>
</html>

------------------
n this my servlet upload.java
-----------------------------------

package controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class upload extends HttpServlet {


@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
String imageUrl = request.getParameter("file");
Connection connection = null;
String connectionURL = "jdbc:mysql://127.0.0.1:3306/skill_tracker";
ResultSet rs = null;
PreparedStatement psmnt = null;


// declare FileInputStream object to store binary stream of given image.

try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");

// create a file object for image by specifying full path of image as parameter.
File image = new File(imageUrl);
//String ab = image.getCanonicalPath();
FileInputStream fis = new FileInputStream(image);
psmnt = connection.prepareStatement("insert into pic values(?,?)");
psmnt.setInt(1,'1');
psmnt.setBinaryStream (2, (InputStream)fis, (int)(image.length()));
/* executeUpdate() method execute specified sql query. Here this query
insert data and image from specified address. */
int s = psmnt.executeUpdate();
if(s>0) {
out.println("Uploaded successfully !");
}
else {
out.println("unsucessfull to upload image.");
}
}
catch (Exception ex)
{
out.println("Found some error : "+ex);
}
}
}

11 years ago
JSP