BROWSE BUTTON CODE

BROWSE BUTTON CODE

HOW TO STORE THE FILE BROWSE TO THE DATABASE

View Answers

February 23, 2011 at 11:18 AM

JSP File Upload

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:
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
Advertisements
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
Browse Button Enlarge Field - Development process
Browse Button Enlarge Field  How can I enlarge the browse text field... the browse button and selecting my document, only about 20 characters... data in the field.   Hi friend, Code for Browse the file
creating browse button - Java Beginners
creating browse button  how can we create a browse button along... ActionListener { JButton button; JTextField field; public BrowsePath () { this.setLayout(null); button = new JButton("browse
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP  I am using the following code snippet.... Is it not possible to use a image instead of normal html Browse button for uploading files
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
facebook like button code
facebook like button code  How to create a facebook like button? can anyone share the code..?? Thanks in advance
inserting image in mysql database using browse button in servlets
inserting image in mysql database using browse button in servlets  Hi,I want to insert a image in mysql database using browse button. and, i want to display all inserted images in a form from there i want to download the image
code for insert button
code for insert button    i want code for insert button(in image...;The given code uses Swing components to create a image button and allow the user to enter name and address. As the user clicks the image button, the data will get
How to set attachment from browse button to send mails using java mail api
How to set attachment from browse button to send mails using java mail api   Hello Sir, I am making Email Sending app using java mail api... browse button but attachment is not loading properly using browse button because
code to disable back button of browser
code to disable back button of browser  code to disable back button of browser
code to disable back button of browser
code to disable back button of browser  code to disable back button of browser
browse image
browse image  how to browse the image in image box by browse button and save image in database by save button by swing   import java.sql.... img; JTextField text=new JTextField(20); JButton browse,save; JPanel p=new
browse image
browse image  how to browse the image in image box by browse button and save image in database by save button by swing   import java.sql.... img; JTextField text=new JTextField(20); JButton browse,save; JPanel p=new
Browse an image
Browse an image  hi................ i want to browse an image from... text=new JTextField(20); JButton browse,save; JPanel p=new JPanel(new... UploadImage() { browse = new JButton("Upload"); save = new JButton("Save
in the below code two errors are there one at the button onclick atttibute and the next is at the next button
in the below code two errors are there one at the button onclick atttibute and the next is at the next button  <%@ page import="java.sql.*" %> function editRecord(id){ var f=document.form; f.method="post
browse and submit the excel sheet into mysql as a table
browse and submit the excel sheet into mysql as a table  sir, i want to browse and after clicking a submit button, the data in the excel sheet should be stored in the mysql5.0 as a table
ModuleNotFoundError: No module named 'browse'
ModuleNotFoundError: No module named 'browse'  Hi, My Python... 'browse' How to remove the ModuleNotFoundError: No module named 'browse'... to install padas library. You can install browse python with following command
ModuleNotFoundError: No module named 'browse'
ModuleNotFoundError: No module named 'browse'  Hi, My Python... 'browse' How to remove the ModuleNotFoundError: No module named 'browse'... to install padas library. You can install browse python with following command
Button
Button  How to use image for button in JSF
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
ModuleNotFoundError: No module named 'git-browse'
ModuleNotFoundError: No module named 'git-browse'  Hi, My Python... 'git-browse' How to remove the ModuleNotFoundError: No module named 'git-browse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'git-browse'
ModuleNotFoundError: No module named 'git-browse'  Hi, My Python... 'git-browse' How to remove the ModuleNotFoundError: No module named 'git-browse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'git-browse'
ModuleNotFoundError: No module named 'git-browse'  Hi, My Python... 'git-browse' How to remove the ModuleNotFoundError: No module named 'git-browse' error? Thanks   Hi, In your python environment you
browse a file with java - Development process
browse a file with java  I want to count the number of white line and comment line in a file type with sql with java
how to browse the general files which are in system using java? - Java Beginners
how to browse the general files which are in system using java?  how to browse the general files which are in system using java? its just like in ms word if we click open button from file menu then one window will open
Java file browse
Java file browse In this section, you will learn how to browse a file and allows the user to choose a file. Description of code GUI provide File choosers... Here is the code: import java.io.*; import javax.swing.*; public class
how to browse folder and directory in jsp
how to browse folder and directory in jsp  how to browse folder and directory in my jsp page.i have done my coding part for browsing directory but dont know how to get files after that.and also i want to show limited directories
ModuleNotFoundError: No module named 'npm-browse-cli'
ModuleNotFoundError: No module named 'npm-browse-cli'  Hi, My... named 'npm-browse-cli' How to remove the ModuleNotFoundError: No module named 'npm-browse-cli' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'npmjs-browse-cli'
ModuleNotFoundError: No module named 'npmjs-browse-cli'  Hi, My... named 'npmjs-browse-cli' How to remove the ModuleNotFoundError: No module named 'npmjs-browse-cli' error? Thanks   Hi, In your
Maven Dependency box-android-browse-sdk >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of com.box >> box-android-browse-sdk version1.1.0 in your project
Maven Dependency box-android-browse-sdk >> 2.0.0
You should include the dependency code given in this page to add Maven Dependency of com.box >> box-android-browse-sdk version2.0.0 in your project
Maven Dependency box-android-browse-sdk >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of com.box >> box-android-browse-sdk version1.1.1 in your project
Maven Dependency box-android-browse-sdk >> 1.1.2
You should include the dependency code given in this page to add Maven Dependency of com.box >> box-android-browse-sdk version1.1.2 in your project
Maven Dependency box-android-browse-sdk >> 2.0.1
You should include the dependency code given in this page to add Maven Dependency of com.box >> box-android-browse-sdk version2.0.1 in your project
Version of com.box>box-android-browse-sdk dependency
List of Version of com.box>box-android-browse-sdk dependency
Browse Excel File Problem - Development process
Browse Excel File Problem  I am using a web application,in which i have to browse an excel file columns. It is working in my system. But if i access... displayed when i browse the file. What is the problem?  Hi Friend
Code
Code  code for connecting c lang to database

Ads