Ramsai Palchuri
Jsp Upload
2 Answer(s)      2 years and a month ago
Posted in : JSP-Servlet

<p>multipart\form-data; boundary=----WebKitFormBoundaryq38tlHi55oATzZ7S (The system cannot find the path specified)
I had got an error when  Uploading to an database Mysql
the code is given below</p>

<p><html><body>
&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
&lt;%@ page import="java.io.*" %>
&lt;%</p>

<pre class="prettyprint">String contentType = request.getContentType();
FileInputStream fis;

if ((contentType != null) &amp;&amp; (contentType.indexOf("multipart/form-data") &gt;= 0)) {
    File image=new File(contentType);


    PreparedStatement psmt=null; 
    Class.forName("org.gjt.mm.mysql.Driver");

    Connection con = 
      DriverManager.getConnection(
        "jdbc:mysql://localhost:4040/", "root", "hp");
        psmt=con.prepareStatement("insert into gallery values(?)"); 
    fis=new FileInputStream(image); 


        psmt.setBinaryStream(3, (InputStream)fis, (int)(image.length())); 

        int s = psmt.executeUpdate(); 
        if(s&gt;0) {
</code></pre>

<p>%> 
<b><font color="Blue"> 
&lt;% out.println("Image Uploaded successfully !"); %> 
</font></b> 
&lt;% 
}</p>

<p>else { </p>

<p>out.println("unsucessfull to upload image."); </p>

<p>}</p>

<p>con.close();</p>

<p>psmt.close();
    }
%>
</html></body></p>
View Answers

April 6, 2011 at 10:29 AM


1)page.jsp:

<%@ page language="java" %>
<HTML>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<BODY> <FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<br><br><br>
<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 colspan="2" align="center"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Send File"> </td>
</tr>
<table>
</center>
</FORM>
</BODY>
</HTML>

2)upload.jsp:

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
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(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>
<%
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/test";
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
File f = new File(saveFile);
psmnt = connection.prepareStatement("insert into file(file_data) values(?)");
fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
if(s>0){
System.out.println("Uploaded successfully !");
}
else{
System.out.println("Error!");
}
}
catch(Exception e){e.printStackTrace();}
}
%>

For the above code, we have created the following table:

CREATE TABLE `file` (                                    
          `id` bigint(50) NOT NULL auto_increment,               
          `file_data` longblob,                                  
          PRIMARY KEY  (`id`)                                    
        );

May 17, 2013 at 7:22 PM


Hello, thnks you ! your exemple was very helpful, but how we can upload the files just uploaded ??? and thnks you very much have a good day :)









Related Pages:
Jsp Upload
Jsp Upload  <p>multipart\form-data; boundary...; <p>else { </p> <p>out.println("unsucessfull to upload...;<TITLE>Display file upload form to the user</TITLE></HEAD>
jsp upload file to server
jsp upload file to server  How to create and upload file to server in JSP?   Find the given example that explains how to upload single and multiple file on server using JSP
upload - JSP-Servlet
Upload jar file  What is the steps to upload Jar file in Java
upload images - JSP-Servlet
upload images  How to write the jsp code to upload images...://www.roseindia.net/jsp/upload-insert-csv.shtml Thanks... to upload any file therefor it can also upload an image and can insert
image upload in webapp/upload folder
image upload in webapp/upload folder  sir i want to store upload image in my project directory WebApp/Upload_image/ pls send the jsp servlet code when i upload the image one error found "system cannot found the specified path
Upload the picture - JSP-Servlet
://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml Thanks RoseIndia...Upload the picture  Dear Sir, How to upload the picture in the database a webpage and i want to show that picture another page. what i
Image upload file - JSP-Servlet
Image upload file  I want a code for image upload jsp or servlet.  Hi friend, For image upload jsp or servlet visit to : http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml http
upload video
upload video  hi sir i want to code of upload and download video in mysql database using jsp... and plz give advice which data type is used to store video in table
upload to database - JSP-Servlet
upload to database  hai friends i have a query that is i have to upload a pdf file into database(sqlserver2000) using jsp. In roseindia some examples i seen that is only for uploading into the server but i need the uploaded file
File upload in JSP
File upload in JSP  hi! In my previous interview i got two questions which i could not answer regarding file upload and annotations. I want to know which is the best method can be used for file upload. Whether moving them
Multiple upload - JSP-Servlet
Multiple upload  Hello everyone and Deepak i am using jsp and mysql I am using the program published on roseindia.net of Multiple upload and i am facing an error as given below please help and reply soon this is my 8th
upload csv to mysql db using jsp upload
upload csv to mysql db using jsp upload  Hello all, Please give me the code to uplad .csv from jsp page and insert values into MySQl db. I have a table with 8 cloumns.(MDN--varchar(30),Otafdate date,crt varchar(30),dmdn
File upload - JSP-Servlet
File upload  I am trying to do a file upload program. But, it shows... ----------------------------------------------------------------------------- Display file upload form to the user <... the file To Upload
load and upload. - JSP-Servlet
load and upload.  dear sir, plz give me the sol for my problem.i m waiting for u r reply. why u not replying ..   Hi Friend, We haven't remember your problem. So please send it again. Thanks
File Upload - JSP-Servlet
File Upload  Hi everyone, I am facing file uploading problem.the multiple file upload code of roseindia is working on localhost but the same code is not working on server.i think the package commons-fileupload-1.2.jar
Upload and Download in JSP - JSP-Servlet
and downloading a file in JSP.. When the admin clicks upload, he must be able to upload.... Please visit for more information. http://www.roseindia.net/jsp/file_upload...Upload and Download in JSP  Respected Sir/Madam, I am
File upload - JSP-Servlet
File Uload Using JSP   Choose the file To Upload...File upload  Hello Friends, In my JSP project i want to do a file upload part. For this, i designed two files one for input and other
file upload using JSP
file upload using JSP  I have created a form to upload a file in a html page, now i want to get the path of the file in a jsp page so what code...="java" %> <HTML> <HEAD><TITLE>Display file upload form
Photo Upload - JSP-Servlet
for image upload and download using Servle/jsp. Thanks&Regards, VijayaBabu.M  Hi <% //to get the content type information from JSP Request...(); %> You have successfully upload the file by the name
upload and download files - JSP-Servlet
and download files in JSP visit to : http://www.roseindia.net/jsp/file_upload...upload and download files  HI!! how can I upload (more than 1 file) and download the files using jsp. Is any lib folders to be pasted? kindly
image upload
in oracle or my sql. kindly help me.   JSP Upload file and save file path...image upload  Hello sir I want to upload image or any other type of file on website using jsp and servlet but the condition is that the file should
upload image using JSP Hibernate
upload image using JSP Hibernate  sir, I want to take image from user and save to database(MYSQL) using Hibernate and JSP Thanks in advance
Upload image
help me.  Jsp Upload Image 1)page.jsp: <%@ page language="java...Upload image  Hai team, I beginner of Java me now i crated code for to capture image and upload to server. Here i taken a snap but when am going
file upload error - JSP-Servlet
file upload error  Hello friends, In my project when i am trying to upload a file i used the roseindia.net coding from URL: http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml
file upload
file upload  how to recieve the uploaded file on the next jsp page for modification if its uploaded to the previous page using a from
upload image
upload image  how can i retreive image from mysql using jsp in netbeans.The image type is varchar with size 200.the image is uploaded succesfully.The problem is when i use the retreival code,it displays only a small box instead
image upload with jsp from form
image upload with jsp from form  hi i used the code specified in your following post http://www.roseindia.net/answers/viewqa/JSP-Servlet/9749-image...) org.apache.jsp.upload_jsp._jspService(upload_jsp.java:85
upload and save the file
upload and save the file  upload and save a file from a computer to specific location of remote computer using jsp
file upload error - JSP-Servlet
file upload error  Iam doing jsp project. File uploading is one part of the project. In this particular part i got an error... ----------- file upload example
image upload
image upload  How to access image file from database using jsp?   retrieveimage.jsp: <%@page import="java.sql.*,java.io.*"%> <% try{ InputStream sImage; Class.forName("com.mysql.jdbc.Driver
file upload in jsp - Java Beginners
file upload in jsp  how to upload a file using jsp. my operating...: Display file upload form to the user UPLOAD THE FILE   Choose the file To Upload:   2
File Upload in FTP - JSP-Servlet
File Upload in FTP  hi sir, i am doing upload files in FTP using java application. is there any jar file to use the privileges of sun.net.ftp. i am writing my program in java servlet. i am getting errors like 1.cannot Find
file upload in jsp - Java Beginners
file upload in jsp  how to upload a file in jsp and store it in my project directory  Hi Friend, We have modified 'upload.jsp...)); fileOut.flush(); fileOut.close(); %>You have successfully upload
File Upload And download JSP Urgent - JSP-Servlet
File Upload And download JSP Urgent  Respected Sir/Madam, I... for it.. In the same application, I need the coding for File Upload and File Download in JSP.. In the Admin window, There must be "Upload" provision where admin
File Upload Tutorial With Examples In JSP
File Upload Tutorial With Examples In JSP  ... by Using JSP This tutorial will help you to understand how you can upload a file... in the developing the project in which you have to upload any type of files
Upload and download file - JSP-Servlet
Upload and download file  What is JSP code to upload and download a document in a web page?  Hi Friend, Try the following code to upload the word document file: 1)page.jsp Display file upload form
how to upload a file - JSP-Servlet
how to upload a file  Dear sir, Give me some code...: Display file upload form to the user UPLOAD THE FILE   Choose the file To Upload:   2
upload a file - Framework
. Thankyou in Advance.  Hi friend, For upload a file in JSP visit to : http://www.roseindia.net/jsp/file_upload/index.shtml Thanks...upload a file  Hi to All, I need to upload a file from the client
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp... file upload form to the user</TITLE></HEAD> <
file upload error - JSP-Servlet
file upload error  Iam doing jsp project. File uploading is one part of the project. In this particular part i got an error as ----------------------------------------------------------------------------- org.apache.jasper.JasperException
upload attachment - Spring
upload attachment  java code in register form to upload an attachment storing in blog and clog   Hi Friend, Are you using JSP or Java Swings? Please clarify this. Thanks
upload and download mp3
upload and download mp3   code of upload and download Mp3 file in mysql database using jsp and plz mention which data type used to store mp3 file in mysql database
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
FTP FILE UPload - JSP-Servlet
FTP FILE UPload  Hi sir, i am doing the file upload via ftp. the program compiled well . but while executing i am getting the below errors. exception javax.servlet.ServletException: Servlet execution threw an exception
Mutliple files upload
the following link: http://www.roseindia.net/jsp/file_upload...Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit
Upload and Download multiple files
link: http://www.roseindia.net/jsp/file_upload/uploadingMultipleFiles.shtml...Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc
upload image to database
upload image to database  i am try to upload image to MySql database using netbeans. when jsp execute it return no error. but also data does inserted in database. i am using blob datatype and preopared statement
file upload and insert name into database - JSP-Servlet
  HIread for more information,http://www.roseindia.net/jsp/file_upload...file upload and insert name into database  Hi, I just joined as a fresher and was given task to upload a file and insert its name into database
JSP Upload and Downloading files - JSP-Servlet
JSP Upload and Downloading files  Respected Sir/Madam, Very... and downloading files in JSP, I am facing a problem.. 1) The file name is getting inserted... reference: For Upload: <% int val =0; String contentType

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.