Home Answers Viewqa JSP-Servlet save the uploading image with user specified name

 
 


subha
save the uploading image with user specified name
1 Answer(s)      11 months ago
Posted in : JSP-Servlet

My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name that is with the name that is given in the textbox.please help me

View Answers

May 26, 2012 at 2:36 PM


1)page.jsp:

<%@ page language="java" %>
<HTML>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>  
<% //  for uploading the file we used Encrypt type of multipart/
form-data and input of file type to browse and submit the file %>
  <BODY> <FORM  ENCTYPE="multipart/form-data" ACTION=
"upload.jsp" METHOD=POST>
                <br><br><br>
          <center><table border="2" >
                    <tr><center><td colspan="2"><p align=
"center"><B>PROGRAM FOR UPLOADING THE FILE</B><center></td></tr>
                    <tr><td><b>Choose the file To Upload:</b>
</td>
                    <td><INPUT NAME="F1" TYPE="file"></td></tr>
                                        <tr><td colspan="2">
<p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>
             <table>
     </center>      
     </FORM>
</BODY>
</HTML>

2)upload.jsp:

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>

<% 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);
String 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 f = new File("C:\\"+saveFile);
FileOutputStream fileOut = new FileOutputStream(f);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of:</b>
<% out.println(saveFile);%></td></tr></table>
<%
}

%>









Related Pages:
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
Uploading an image into the table - JSP-Servlet
to the specified database. */ psmnt = connection.prepareStatement ("insert into save_image...Uploading an image into the table  how to upload an image... string of connection url within specified format with machine name, port
Need help in image uploading - JSP-Servlet
upload images to a specified folder and save the path of image in my DB. Its...Need help in image uploading  hii, i have one doubt in uploading... to remote server..??? regards Sreejith Here is my code for image uploading
Problem in uploading image to to mysql database
here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must... = connection.prepareStatement("insert into save_image(name, city, image) values
Problem in uploading image to to mysql database
here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must...); psmnt = connection.prepareStatement("insert into save_image(name, city, image
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open... is open select any image i want to store that selected image into specified
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database... To Upload:</b></td> <td><INPUT NAME="file" TYPE="file">
change the name of the image after uploading the image
change the name of the image after uploading the image   my form consists of a textbox and uploading the image.after uploading the image i want to change the name of the image with the content of the textbox before saving
uploading problem
uploading problem  i use glassfish server.. using netbeans for jsp...()) { String name... curresponding image files start new upload"); %><
Save the content in my wysiwyg editor into specified location of user when clicked on save button in my web page
Save the content in my wysiwyg editor into specified location of user when clicked on save button in my web page  I am using wysiwyg editor... by the user and also can be saved to his location in word document format. Can
i want to save image on server folder. and i want to save URL of this folder and name of image in database
i want to save image on server folder. and i want to save URL of this folder and name of image in database  hi i want to save image on server folder. and i want to save URL of this folder and name of image in database.on click
Uploading Multiple Image On Server?
Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works fine for uploading single image,but it doesn't work with uploading multiple
Uploading an image - JSP-Servlet
Uploading an image  I am doing a jsp project. In this uploading an image is a part. For that i had done a coding for uploading... and uploading is done by different jsp coding. I don't know how to code for file size
Uploading image using jsp
Uploading image using jsp  how to upload image using jsp. Already i tried, But that image file does not read. It returns only -1 without reading that image file ... I want know that solution using by u... Thanks, P.S.N.  
Insert Image into Mysql Database through Simple Java Code
. */ psmnt = connection.prepareStatement ("insert into save_image(name, city... simple java code that how save image into mysql database. Before running this java code you need to create data base and table to save image in same database
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am... If user want to export this chart as GIF format then this chart should be save as a gif image on the server directory. Can any Body help me how can I do it Thanks
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am... If user want to export this chart as GIF format then this chart should be save as a gif image on the server directory. Can any Body help me how can I do it Thanks
FORM Tag Correctly for Uploading Files.
FORM Tag Correctly for Uploading Files.  How To Write the FORM Tag Correctly for Uploading Files?   Hi friends, When you clicks the submit button, files specified in the <INPUT TYPE=FILE...> will be transferred
Full path of image to save it in a folder
Full path of image to save it in a folder  Sir ,I am trying to upload a file but only sends file name as parameter. I want a code that would help me to find that image path &upload it as well. I am just a beginner in jsp
uploading of image showing exception when size increases.
uploading of image showing exception when size increases.  Hi . I have a project in which the user can upload images. it works properly, but when the image size increases to arnd 1 MB or more it shows exception. I am using tomcat
Uploading the file on Server.
the connection of FTP server for user name. upload the file using ftp_put() function.... <?php $ftp_server = "<IP>"; $ftp_user_name = "<...['image']['name']; $sourcefile = $_FILES['image']['name']; // set up basic
Image uploading
Image uploading  Hi,can anyone explain the following code. The code related to uploading an image file to oracle database using java servlet. CODE import java.io.*; import java.io.IOException; import
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Dear All, I am facing some problem image uploading in server that i working fine in my system, OS Ubuntu... to save images on this path. please help me.. thanks in advance 
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  dear friend... following is my uploading code and i want to save some records....... while submitting time i am getting following error.................. HTTP
How to store user name,city,state,image path into database and image into folder using jsp
How to store user name,city,state,image path into database and image into folder using jsp  How to store user name,city,state,image path into database and image into folder using jsp
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ...*. These are the classes which have been provided to us by the apache to help us in file uploading.... If there is a request for uploading the file then it makes a object of DiskFileItemFactory class
How to save image after edit in php
How to save image after edit in php  Hello, I have create a simple image editor with the effected of brightness, contrast, and desaturat etc. I have... successfully but i don't know how to replace orignal image with the effects. please
rename before uploading
rename before uploading  I need to change (rename)the file name/image name before uploading it so that the file gets uploaded on server with this new name
Uploading website
will ask you for user name and password, provide user name and password... Uploading your website       Uploading Web Site After developing the web
uploading image in php - PHP
uploading image in php  I am looking for a PHP script to upload image into mysql database
query related to uploading file
and file name and path in oracle database.with name file name and path i also want to save the uploading time and date in database. please help me it is urgent...query related to uploading file  hello friends i am doing my
Image uploading in FTP Server
Image uploading in FTP Server  I want to upload images to a ftp server every 1 hour automatically using java..please help
How to upload and save a file in a folder - Java Beginners
How to upload and save a file in a folder  Hi How to upload and save a file in a folder? for example Agreement.jsp File: So when user browses the file and enters the submit button the respective file should
video uploading using jsp
video uploading using jsp  this is the code i hv written for uploading..but the value in dropdown list is not captured..can any 1 tell the reason..." method="POST"> <input type="file" name="file2"><br><
file uploading using jsp
file uploading using jsp  below file uploading code has one error... = fileData + s; pos = fileData.indexOf("Content-Disposition: form-data; name=\""); //set the file name if(pos != -1) endPos = pos; }while(pos
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
file uploading - JSP-Servlet
Employee Name: Employee Address...: Employee Image
error in uploading image from jsp to oracle 10g database
error in uploading image from jsp to oracle 10g database  ... try to insert into the image into the database i got the above error please advice how to get rid of error   JSP upload image in Mysql database
Name
Name  make a program that take a input from user in alphabet and show all the name of that character E.g User give character "B". The program shows... the user and show all the names that starts with that character. class
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
URL file Download and Save in the Local Directory
and save this Url File in the specified directory. This program specifies...URL file Download and Save in the Local Directory   ... and FileOutputStream write the data to the local file in a specified directory. 
image upload
image upload  Hello sir I want to upload image or any other type... in oracle or my sql. kindly help me.   JSP Upload file and save file path to database The given code allow the user to browse and upload selected file
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
uploading a file - JSP-Interview Questions
uploading a file   uploading a file and storing in database using...(File file) { if (file.isDirectory()) return false; String name...())); int s = st.executeUpdate(); JOptionPane.showMessageDialog(null,"image
why java file save as its class name
why java file save as its class name  hi,this is subbareddy vajrala.my doubt is why java files save as its class names
Struts File Upload and Save
Struts File Upload and Save  ... code illustrating how to  save the file on the server . Now, the current... program to upload on the Server and display a link to the user to download

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.