Fileupload from source path to destination path

Fileupload from source path to destination path

first we will create one .doc file and .rtf file in one location statically.In html we will give source path &Destination path fields and BOTH INPUT TYPES ARE "TEXT" we will give source path as statically where the .doc or .rtf files path will be their.and we have to give destination path.After submitting the files have to store in the destination path like if the source file is .doc it will create a DOC folder Dynamically in the destination path and store to that .doc file.If the source file is .rtf it will create a RTF folder dynamecally in destination path and store that .rtf file into that path . please help me...

Thanks in advance.
View Answers

August 2, 2011 at 2:38 PM

1)page.jsp:

<%@ page language="java" %>
<HTML>
<FORM ENCTYPE="multipart/form-data" ACTION="upload.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 colspan="2" align="center"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
<table>
</center>
</FORM>
</HTML>

2)upload.jsp:

<%@ 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(saveFile);
FileOutputStream fileOut = new FileOutputStream("C:/UploadedFiles/"+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";
PreparedStatement psmnt = null;
FileInputStream fis;
InputStream sImage;
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();
}
}
%>









Related Tutorials/Questions & Answers:
Fileupload from source path to destination path
Fileupload from source path to destination path  first we will create... source path &Destination path fields and BOTH INPUT TYPES ARE "TEXT" we... in the destination path like if the source file is .doc it will create a DOC folder
Shortest path in JSP for a given source and destination
the shortest path from the given source to destination based on the databse values. I...Shortest path in JSP for a given source and destination  Hi. Here..., source varchar(45) NOT NULL, destination varchar(45) NOT NULL, distance int(10
Advertisements
Shortest path in JSP for a given source and destination
the shortest path from the given source to destination based on the databse...Shortest path in JSP for a given source and destination  Hi. Here..., source varchar(45) NOT NULL, destination varchar(45) NOT NULL, distance int(10
shortest path from the given source to dstination
to find the shortest path from the given source to destination based...shortest path from the given source to dstination  Hi. Here in my...) unsigned NOT NULL, PRIMARY KEY (id) ); INSERT INTO b (id,source,destination
Path of source code
Description:  This example demonstrate how to get the path of your java program file. The URI represents the abstract pathname and URL construct from URI. Code: import java.io.
How to get full path of the uploaded file using commons fileupload jar file
How to get full path of the uploaded file using commons fileupload jar file  I want to upload file to database with its full path. Because... type.I am in need to get the full path. Can anyone help me to get the full path
Storing content from file path to an array
Storing content from file path to an array  Hi, I have a path... would like to access the "Animation.txt" file from this path and store the contents in this text file to an array. I am using jsp. I can access my path but how
image is display from path of mysql database
image is display from path of mysql database  <%@ page import="java.io.,java.sql.,java.util.zip.*" %> <% String saveFile=""; String..._path) values(?)"); psmnt.setString(1, ff.getPath()); int s = psmnt.executeUpdate
path classpath
path classpath  EXPLAIN PATH AND CLASSPATH ? DIFF send me ans plz..., Path is system wide variable that tells where to find your commands. Lets... be in path. While Classpath is Enviroment Variable that tells JVM or Java Tools where
Path was not found
Path was not found  The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
how to show image as a link which path coming from database
how to show image as a link which path coming from database   iam not getting proper answer for it. I am using netbeans .the url coming instring from database ,want to display as image on jsp . please help me
Read File from specified path in Java
How to read a file from a specified path in Java? After learning so many... reads a text file from specified path in Java. We will give complete path... is a complete example of the program that reads a text file from the disk path and print
absolute path in php - PHP
absolute path in php  how to get absolute path in php
JSP Current Path
illustrate an example from 'JSP Current Path'. In this section, you will learn how... JSP Current Path          JSP Current Path is used to get the current
Path Separator
on the command prompt with appropriate path.  Download Source Code... Path Separator       In this example, path.separator is used to separate the path and file
path setting - JSP-Servlet
path setting  Hi, friends How to set the oracle 10g path on browser to servlet program
ModuleNotFoundError: No module named 'path'
ModuleNotFoundError: No module named 'path'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'path' How to remove the ModuleNotFoundError: No module named 'path' error
path - Java Beginners
meaning of path and classpath  what is the meaning of path and classpath. How it is set in environment variable.  Path and ClassPath in in JAVAJava ClassPath Resources:-http://www.roseindia.net/java/java-classpath.shtml
how to set class path
how to set class path  how to set class path in java
Jsp Absolute Path
The Tutorial illustrate an example from 'JSP Absolute Path'. To understand JSP... Jsp Absolute Path   ... the absolute path in jsp. The absolute path is the full path that contains the root
File path for jar file
not found for the template file. Also I had tried to get that path from user...File path for jar file  Hi Experts, I have created one eclipse... path of the template, which is working as per expectation. But I have created
need solution to get file name from path which should give by user
need solution to get file name from path which should give by user  how do i write a program in java that i should get file path from... source = new DOMSource(doc); transformer.transform(source, result); String
path problem - Java Beginners
path problem  I dont know how to set the path. What path should we...-FINAL-20081019.jar in jdk's lib folder. I entered path as "C:\Program Files\Java\jdk1.6.0_07\lib" , is this correct? Becoz even after this path compilation
Error in context path
Error in context path   I Tried a Struts2 Login application having... = request.getContextPath(); System.out.println("Context Path " + contextPath... ... undeploy?path=/strutsDemo OK - Undeployed application at context path /strutsDemo
PHP hide file path
PHP hide file path  PHP to read a path and convert that to the virtual link
Java Path Class
of Java. In Java, Path class is added from the SE 7 release. Java 7 has added... path of file system of one Operating System is different from the file system... to get the relative path from the current path, the returned path
How to give path to the Dfile?
How to give path to the Dfile?  Hello erveryone, I want to make... on sphinx, i have to give path to the sphinx4.jar file which is present in my... not linux ,i want to try above but in this i can't get the write Dfile path , can
classpath and path for structs1.3.8
classpath and path for structs1.3.8  How to set classpath and path for structs1.3.8 ?   just add struts-core-1.3.8.jar file to CLASSPATH........there is no need of setting path
What is difference between Path and Classpath?
What is difference between Path and Classpath?   hi What is difference between Path and Classpath? thanks   Hi, The Path & Classpath are used for operating system level environment variales. We mostly use Path
path setting - JSP-Servlet
. While setting this path i need to give the full path from drive name, instead...path setting  Hello friends, I download file uploading coding from the following url: http://www.roseindia.net/jsp/file_upload
path setting - JSP-Servlet
setting this path i need to give the full path from drive name, instead of this if i...path setting   Hello friends, I download file uploading coding from the following url: http://www.roseindia.net/jsp/file_upload/Sinle
how to find jdk path in ubuntu?
how to find jdk path in ubuntu?  How to find out the path of installed jdk in ubuntu? Could anyone tell that command to execute from terminal.. Thanks
getting the excel path throuh web browser given from client(i.e thruogh .jsp)
getting the excel path throuh web browser given from client(i.e thruogh .jsp)  1)when client uploads the excel sheet through a .jsp page, 2)get that excel path from web browser and read the data from the excel and printing
Java IO Path
;. Absolute Path : Path for locating a file uses the complete directory path from... : A relative path does not contains the complete directory path from root node...Java IO Path In this section we will discuss about the Java IO Path. Storage
Class Path - Java Beginners
Class Path  Hello I was able to set the class path as You have......; there u can type the path both in user variables for administrator   Hi...-->environment variables--> there u can type the path both in user variables
path - Java Beginners
path  how to set the path in environment variables to run java programs in my pc?   Hi friend, Read for more information. http://www.roseindia.net/java/learn-java-in-a-day/download-and-install-java.shtml
problem in setting path - Ant
the reply its urgent  Hi friend, Your code : i setted the path... this and path=D:\installations\apache-ant-1.7.1-bin\apache-ant-1.7.1\bin;D... Do some changes setting the path : 1)ANT_HOME=D:\installations\apache
How to get project path
How to get project path  my problem is,i have one jar file,in that one xml is their,i am adding this jar file to my project,my question is how i can open or get that xml path
How to get project path
How to get project path  my problem is,i have one jar file,in that one xml is their,i am adding this jar file to my project,my question is how i can open or get that xml path
interview path pdf
interview path pdf  Plz send me the paths of java core questions and answers pdfs or interview questions pdfs... the interview for any company for <1 year experience thanks for all of u in advance   Please visit
Setting of java1.4.2 path
Setting of java1.4.2 path  Hello I have uploaded java1.4.2 into my laptop and i have done path settings for System variabales as Path (C:\j2sdk1.4.2\bin) and classpath(C:\j2sdk1.4.2\lib) .But when i write simple
Add context path to URL for outputLink
Add context path to URL for outputLink  How to add context path to URL for outputLink
Regarding path settings in java
Regarding path settings in java  Hello I had a problem of setting paths in Java.I setted classpath(C:\java\j2sdk1.4.2\lib) and path(c:\java\j2sdk1.4.2\bin) in system variables. But when i compile simple java progrm
How to use Java Path class?
dependent, i.e. path of file system of one Operating System is different from...) This method is used to get the relative path from the current path, the returned path is the subsequence of the current path returned from the specified index
No SDK with the name or path
or path....version xyz. Base SDK Missing. What is this error and how can i set... Missing or No SDK with the name or path for XYZ version follow the steps below
No action instance for path
;% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <...; </form-beans> <action-mappings> <action path
to obtain image path
or BROWSE button . and i am expecting to obtain the complete path of the image from...to obtain image path   i have made a web application in which you can..."); // create a file object for image by specifying full path of image
How to store url path?
How to store url path?  Image is stored in physical directory like this String file = "C:/xampp/htdocs/jobqueen/" + username + createTimeStampStr... path like this String file = "http://www.queen.com/website/screenshots/" + username
ModuleNotFoundError: No module named 'critical-path'
ModuleNotFoundError: No module named 'critical-path'  Hi, My... 'critical-path' How to remove the ModuleNotFoundError: No module named 'critical-path' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'floweaver-path'
ModuleNotFoundError: No module named 'floweaver-path'  Hi, My... named 'floweaver-path' How to remove the ModuleNotFoundError: No module named 'floweaver-path' error? Thanks   Hi, In your python

Ads