which path we have to give in order to upload a file from any where in the system

which path we have to give in order to upload a file from any where in the system

When i am uploading an image to MySQL database in this i am to specifying a path in the code from that path only it is taking image . what i have to do in order to upload a image from any where from the system Please tell me quickly i need it

View Answers

February 6, 2012 at 11:45 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.*" %>
<%@ page import="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(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();}
}
%>









Related Tutorials/Questions & Answers:
which path we have to give in order to upload a file from any where in the system
which path we have to give in order to upload a file from any where... to specifying a path in the code from that path only it is taking image . what i have to do in order to upload a image from any where from the system Please tell me
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 arguments.currently this code creates the file at d:\ but i need to get this file name
Advertisements
Web Service - Which files we have to give to client and how they will use that
Web Service - Which files we have to give to client and how they will use... this web service or want to give it to client , for that which files i have to give... and have to use it, how we call this in jsp/servlet 3) Which type of response we
which values we have to use for compressing any color image
which values we have to use for compressing any color image  Sir........... in the process of compressing of any color image, which values do use as input for comprseeing algorithm. and how to get the image matrix from color
about Detail file path where to store application.
about Detail file path where to store application.  can you tell me detail path where we have to store our application
executing a batch file which depends on jar files from a system tray but console should not display.
executing a batch file which depends on jar files from a system tray... to run a batch file which is depending on some jar files and it displays a frame and some output generated by System.out.println()'s from system tray. I want
How to give path to the Dfile?
on sphinx, i have to give path to the sphinx4.jar file which is present in my...How to give path to the Dfile?  Hello erveryone, I want to make... to try above but in this i can't get the write Dfile path , can you give me
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
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
File Upload Tutorial With Examples In JSP
in the developing the project in which you have to upload any type of files... File Upload Tutorial With Examples In JSP  ... by Using JSP This tutorial will help you to understand how you can upload a file
Java Get File Name
Java Get File Name       In this section, you will study how to obtain the name of file.  In order to get the file name, we have provided the path of file 'Hello.txt
which is good hadoop file system commands tutorial
which is good hadoop file system commands tutorial  Hi, I am learning hadoop file system commands and trying to find all commands of hadoop with examples. which is good hadoop file system tutorial? Thanks   Hi
which is good hadoop file system commands tutorial
which is good hadoop file system commands tutorial  Hi, I am learning hadoop file system commands and trying to find all commands of hadoop with examples. which is good hadoop file system tutorial? Thanks   Hi
Read File from specified path in Java
How to read a file from a specified path in Java? After learning so many examples of file handling in  Java, we will show to a simple program which reads a text file from specified path in Java. We will give complete path
in unix which command is used to sort the lines of data in a file in reverse order
in unix which command is used to sort the lines of data in a file in reverse order  in unix which command is used to sort the lines of data in a file... the lines of data in a file in reverse order
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
why and where we use setter and getter methods in java, please give me one example program.....
why and where we use setter and getter methods in java, please give me one example program.....  why and where we use setter and getter methods in java, please give me one example program
Write a method which will remove any given character from a string?
Write a method which will remove any given character from a string? In this example we will describe remove any given character from a string. In this tutorial we have used StringBuilder is a mutable sequence of character. It is used
Struts 2 File Upload
. The Struts 2 File Upload Interceptor is based on MultiPartRequestWrapper, which... the allowed content type. Writing Example code to upload file Now we will write... class we will define four properties to facilitate the file upload. private File
Java Construct File Path
; (separator character). But, we can construct a file path system independent due...Java Construct File Path In this section we will discuss about how.... When you will construct a file path manually the path name will be system
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... will give source path as statically where the .doc or .rtf files path will be their.and
File Upload
File Upload  when i execute the image upload to mysql database it shows an exception that file path cannot be found
How and Where we Access struts Properties file - Struts
How and Where we Access struts Properties file   Hi Friends, am new...) and for future enhancements we just call properties file . Now i want to implement this , where can i call properties file to enhance my application. My question
Java example to get the execution path
;     get execution path We can get the execution path of the system in java by using the system property. For getting execution path we have used "user.dir" property of the system. Here
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload  Dear Sir, My issue is: How display a image on servlet from file upload I receive your answer today... is not running mode which you give me. I am using weblogic 8.1 have jdk 1.4. I
File path for jar file
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... not found for the template file. Also I had tried to get that path from user
SWT File Browser
, the class FileDialog allow the user to navigate the file system and select a file name. In order to layout the text, we have used the method text.setLayoutData...;= new File(path);   if (file.isFile())   
how to upload a file of apk format in a folder from servlet
how to upload a file of apk format in a folder from servlet  How to upload a file of apk format to a folder from servlet, i am trying to do, its getting uploaded as .zip file and not apk file
How to play only video file from any link
How to play only video file from any link  Hi Friends Please Help Me. My requirement is to play only videos from any webpages(ITS NOT A ABSOLUTE PATH)[IF I PASTE any VRL---,IT HAS TO BE PLAY IN ANY CONTROL] how it possible
How to upload zip file from android to server programmatically?????
How to upload zip file from android to server programmatically?????  hi , I want to upload zip file from android phone sdcard to server programmatically. So any one do this task in past so please share your experience with me
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload   Dear Sir, My Question is: How display a image on servlet from file upload Your Answer: Hi... of file. like any .jpg, .txt. Servlet page dispaly empty in each cases
We just have one file on the hard disk. But we can create directories, sub-directories and files in that file only
We just have one file on the hard disk. But we can create directories, sub-directories and files in that file only  We just have one file on the hard disk. But we can create directories, sub-directories and files in that file
We just have one file on the hard disk. But we can create directories, sub-directories and files in that file only
We just have one file on the hard disk. But we can create directories, sub-directories and files in that file only  We just have one file on the hard disk. But we can create directories, sub-directories and files in that file
Order Entry System
Order Entry System  Create a new order entry system using netbeans and microsoft access.can anyone help me
How to upload and download file in hadoop?
; Hi, Hadoop provides the Hadoop File system which is known as HDFS and its.../filename> /<hdfs path/> Above command will upload the file on Hadoop...How to upload and download file in hadoop?  Hi, I am trying to learn
any body have any solutions?
any body have any solutions?  Hi Friends, I just get down my computer, I am working on it, but suddenly get down and can√Ę‚?¨‚?Ęt get start again. If any body have any solutions
Java program to get the desktop Path
;     In this example program we have to get the desktop path of the system. In the java environment we can get the desktop path also with the system's property. For getting the desktop path we have to add
How display a Image on servlet from file upload - JSP-Servlet
How display a Image on servlet from file upload  Dear Sir, I were ask a question that How display the Image on servlet through file upload. Today I... -------------------------------------------- If you have any problem then explain
Java Read Lines from Text File and Output in Reverse order to a Different Text File
Java Read Lines from Text File and Output in Reverse order to a Different Text... the JButton. Each line in the file then needs to be converted in Reverse Order... to display the names and path on the console. But I can not get the file to read line
where this file is stored
where this file is stored  thank your sir, but where this file is stored? and how to get the path for further use
where to stroe this uploaded file
where to stroe this uploaded file  thank your sir, but where this file is stored? and how to get the path for further use
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both  How to include Two multi rows, one with a file Upload and another with normal fields, have problem while
ModuleNotFoundError: No module named 'django-upload-path'
ModuleNotFoundError: No module named 'django-upload-path'  Hi, My... named 'django-upload-path' How to remove the ModuleNotFoundError: No module named 'django-upload-path' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-uuid-upload-path'
ModuleNotFoundError: No module named 'django-uuid-upload-path'  Hi...: No module named 'django-uuid-upload-path' How to remove the ModuleNotFoundError: No module named 'django-uuid-upload-path' error? Thanks   
ModuleNotFoundError: No module named 'django-uuid-upload-path'
ModuleNotFoundError: No module named 'django-uuid-upload-path'  Hi...: No module named 'django-uuid-upload-path' How to remove the ModuleNotFoundError: No module named 'django-uuid-upload-path' error? Thanks   
ModuleNotFoundError: No module named 'upload-path-pyramid'
ModuleNotFoundError: No module named 'upload-path-pyramid'  Hi, My... named 'upload-path-pyramid' How to remove the ModuleNotFoundError: No module named 'upload-path-pyramid' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-upload-path-generator'
ModuleNotFoundError: No module named 'django-upload-path-generator'  ...: No module named 'django-upload-path-generator' How to remove the ModuleNotFoundError: No module named 'django-upload-path-generator' error
ModuleNotFoundError: No module named 'django-uuid-upload-path'
ModuleNotFoundError: No module named 'django-uuid-upload-path'  Hi...: No module named 'django-uuid-upload-path' How to remove the ModuleNotFoundError: No module named 'django-uuid-upload-path' error? Thanks   
From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator.
perform different roles. From a security point of view, we can say.... The system administrator tells the application server where to find... of an application must have in order to successfully use the application
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

Ads