I cant getting parameter values from an<html>
1stPage:
<HTML>
<FORM ENCTYPE="multipart/form-data" ACTION="saveImage.jsp" METHOD=POST>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr>
<center><td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
<tr><td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file"></td>
</tr>
<tr><td><b>Enter Car Id:</b></td>
<td><INPUT type="text" name="id"></td></tr>
<tr><td><b>Enter Car Name:</b></td>
<td><INPUT type="text" name="names"></td></tr>
<tr><td><b>Enter Car Description:</b></td>
<td>
<textarea type="text"rows="9" cols="27" name="desc">
</textarea>
</td></tr>
<tr><td colspan="2" align="center"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
</table>
</center>
</FORM>
</HTML>
2nd Page
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*,java.sql.*,java.util.zip.*" %>
<%
String saveFile="";
String contentType = request.getContentType();
if((contentType != null)&&(contentType.indexOf("multipart/form-data") >= 0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
File ff = new File("C:/UploadedFiles/"+saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%><br><table border="2"><tr><td><b>You have successfully upload the file:</b>
<%out.println(saveFile);%></td></tr></table>
<%String jid = request.getParameter("id");
String jname = request.getParameter("name");
String jdesc = request.getParameter("desc");
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/mynewdatabase";
PreparedStatement psmnt = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection(connectionURL, "root", "root");
psmnt = connection.prepareStatement("insert into newcar(Car_Name,Car_Image,Car_Desc,Car_Id) values(?,?,?,?)");
psmnt.setString(1, jname);
psmnt.setString(2, ff.getPath());
psmnt.setString(3,jdesc);
psmnt.setString(4,jid);
out.println("sara insert after");
int s=psmnt.executeUpdate();
out.println( "after execute");
if(s>0)
{
out.println("Uploaded successfully saravanan!");
}
else{
out.println("Error!");
}
}
catch(Exception e){
out.println( e);
}
}
%>
</body>
</html>
other jsp page,but i am getting images correctly...Here is my code..