Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process Fileupload from source path to destination path

Have Programming Question? Ask it here!
 
 
 


kodesudheer
Fileupload from source path to destination path
1 Answer(s)      2 years and 9 months ago
Posted in : Development process


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.

Advertisement
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
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
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.
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
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
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
absolute path in php - PHP
absolute path in php  how to get absolute path in php
JSP Current Path
from 'JSP Current Path'. In this section, you will learn how to get the current... JSP Current Path          JSP Current Path is used to get the current
Path Separator
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
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
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
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
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
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
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
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
Jsp Absolute Path
illustrate an example from 'JSP Absolute Path'. To understand JSP Absolute Path example... Jsp Absolute Path   ... the absolute path in jsp. The absolute path is the full path that contains the root
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
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
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
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
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
Java IO Path
a file uses the complete directory path from root node to file is an absolute... not contains the complete directory path from root node to the file which has...Java IO Path In this section we will discuss about the Java IO Path. Storage
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
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... beginIndex, int endIndex) This method is used to get the relative path from
No action instance for path
;% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <...; </form-beans> <action-mappings> <action path
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
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
Add context path to URL for outputLink
Add context path to URL for outputLink  How to add context path to URL for outputLink
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
Class path
file may start from a different directory in the class path. Folders... Class path       The Classpath is an argument that is path through the command line. Classpath can
Getting a absolute path
Getting a absolute path     ... the path of the file or directory so that you can access it. If you know the path... in front you where you don't know the path of the file, then what will you do
Modifying the Path Example.
Modifying the Path In this example, you will learn how to modify the corrupted path using $outpath command in PHP. This command will modify the path in the correct way if it finds any error syntax in the defined path. The $outpath command
File Path compare in java
File Path Comparison :compareTo      File Path Comparison :compareTo... of their path.  For this purpose, we use   compareTo() method
poi & class path - Java Beginners
have downloaded poi-bin-3.5-beta6-20090622.zip from this link http... this is the correct link, so please suggest a link from where i can download those required files. Also after downloading how to set class path.  Hi Friend
Eclipse current project(Workspace) path
Eclipse current project(Workspace) path  Hello, I want to use a path... it ??? I use getServletContext.getRealPath() but it gives me path of deployed project means ".metadata.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\" path
How to find unweighted Path with Less weighted path in java?
How to find unweighted Path with Less weighted path in java?  I have methods to find weighted and unweighted(Djistra) so I to output unweighted path that has less weighted cost...e.g if I have A->B->C and A->F->C
 

 

 

DMCA.com