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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kodesudheer
Fileupload from source path to destination path
1 Answer(s)      3 years and 2 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
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
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
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
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
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
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
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
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
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
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
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
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
 

 

 

DMCA.com