jsp-file

jsp-file

i want to upload a file by browse button and the file should be save in ms access database.....how i can implement trough jsp plz help me sir............

View Answers

September 14, 2011 at 5:04 PM

Follow these steps:

1)create table file(id,file_data). id should of AutoNumber type and file_data should of text type if file is text file, otherwise oleobject.

2)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.*" %>
<%
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>
<%
PreparedStatement psmnt = null;
FileInputStream fis;
InputStream sImage;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
File f = new File(saveFile);
psmnt = con.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:
JSP File
JSP File  Hi, What is JSP File? How to create JSP file? Thanks   Hi, JSP file is simple text file with .jsp extenstion. You can run JSP file on tomcat server. Read more at JSP tutorials section. Thanks
written in jsp file
written in jsp file  how to create and write in a jsp file through simple core java code
Advertisements
run jsp file
run jsp file  how to run the jsp file in varies web servers  ... the class path also. The jsp file is to be saved into the web application folder.Let the file be 'abc.jsp' and web application folder be 'examples'. Start the tomcat
include a jsp file
include a jsp file   Sir, I have 2 jsp pages. I want to include second jsp in the first jsp page when a button in the first jsp is clicked. how can I do this. I tried in sevaral ways . I am using jsp and javascript... anyone
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I am able to create jsp file in java that includes ; table tr td and img tags..... Need to include jsp file in the same content. The below code doesn't help me
I have doubt in jsp file.
I have doubt in jsp file.  I have doubt in jsp file. In a jsp file, there should be two buttons. One is start and other is stop. When we click on start then only stop should be enabled. Other wise it should be disabled. When
Java to create table in jsp file that include other jsp file
Java to create table in jsp file that include other jsp file  String jspContent = "table" += "tr" += "td" += "jsp:include page='fileSource'" //this line is not working properly... += "/td" += "/tr>" += "/table" Please refer
Add a jsp file to java application
Add a jsp file to java application  How to add a JSP file to java...;%@include file="success.jsp" %><br/> <h2>Here You are including a Jsp... the contents of the named file into the JSP containing the tag.You can say
JSP file download - JSP-Servlet
JSP file download  Hi! I am saving (webapp/docs/sample.docx) path of the word file in database. when i want to download that file i am eliminating that file path using path.subString(16).. upto docs/. when i am clicking
Create JSP file
Create a JSP file To create a JSP file for struts, Some special (Struts specific) tags are used. And to use those tags in JSP you need to import there tag... for StrutsPrepareAndExecuteFilter in web.xml file. as <filter> <filter-name>struts2
jsp-file
jsp-file  i want to upload a file by browse button and the file should be save in ms access database.....how i can implement trough jsp plz help me sir
pasing variables in jsp file - JSP-Servlet
files share variables and how can one pass local variables from one jsp file to another jsp file?  Hi Friend, To pass variables from JSP file to another JSP file ,do the following: 1) create jsp page 'passVariable.jsp'and use
To run a jsp file automatically - IDE Questions
To run a jsp file automatically  Hi all, I am in need for the solution for - Can a JSP page can be made to run automatically when NetBeans IDE has been started. or we have to compile and run it automatically? I
Jsp error when i run this a jsp file
Jsp error when i run this a jsp file  hi I got this error when i run the jsp file in IDE and outside also please help me java.lang.NullPointerException org.apache.jsp.insertjsp.jspInit(insert_jsp.java:22
Error in loading jsp file - JSP-Servlet
Error in loading jsp file  I did as u have said. I copied iitem.jsp in webapps\examples\jsp and item.java in webapps\examples\WEB-INF\classes\form. I ran the jsp file by typing the following address in the address bar: http
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file . look at the line with code-> Statement st=con.createStatement(); in the below example. the error is "cannot convert from java.sql.Statement
delete retailer jsp file (sir..is this a good logic.. jsp file is useful for what purpose)
delete retailer jsp file (sir..is this a good logic.. jsp file is useful for what purpose)  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http
common database jsp file for all the jsp files in the application
common database jsp file for all the jsp files in the application  hi... use of this single jsp file while connecting to database rather than writing connectivity code in all the jsp pages . send me the code for that . thanks
callig jsp file from javascript function - JSP-Servlet
callig jsp file from javascript function  I want to call a jsp file... on a form in html, the function should call specified jsp file.The form has no dynamic data, no button and no links. Is it possible to call jsp page from static html
jsp file - JSP-Servlet
jsp file  org.apache.jasper.JasperException: /jsp/admin/UserRegistration.jsp(155,4) According to the TLD or the tag file, attribute valu e... org.apache.jasper.JasperException: /jsp/admin/UserRegistration.jsp(155,4) According
linking tree heading in javasript into a Jsp file and then jsp to struts action form
linking tree heading in javasript into a Jsp file and then jsp to struts action form  i have a tree that consists of 3 options say for example 1... to the corresponding jsp say 1) aaa_jsp.jsp 2) bbb_jsp.jsp 3) ccc_jsp.jsp how
not able to get values from jsp file - JSP-Servlet
not able to get values from jsp file  hi thanks for u feedback, her am sending the file jsp and servlet but in the servlet file am not able to get... and reply me its urgent.. jsp file ========= Display file upload form
view jsp file (reference file). is the way of coding good ?
view jsp file (reference file). is the way of coding good ?  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> View Retailer <%@ page import="com.tcs.ilp.*" %>
Getting Parameter from a css styled jsp file to a java servlet file...
Getting Parameter from a css styled jsp file to a java servlet file... ...; java servlet file-- /* * To change this template, choose Tools... is it not getting the parameter??? How do i accept the value in the servlet file
passing values between jsp file through hyperlink in div tag
passing values between jsp file through hyperlink in div tag  <...;script src="js/AdminHeader.js"&gt;&lt;/script&gt; &lt;jsp:include page="/jsp/admin/Adminmenu.jsp" &gt; &lt;/jsp:include&gt
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file..." in a text-box in a JSP file. Ex:dept table; if we give dept_no in a text-box in JSP... it in the same JSP file. Help me plz
Passing a 2 Dimentional Array From one Jsp to Another Jsp file and Retreving it
Passing a 2 Dimentional Array From one Jsp to Another Jsp file and Retreving... are dynamically stored into it in one jsp file .I passed this array into another Jsp... JSP FILE 1 : // declatarion int final
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.  i have MYSQL DB,DB NAME:TRLIST, TABLE NAME:TR_LIST; (FIELD NAMES:NODE,PACKAGE,TR), {VALUES:Row1(CCN,CS4.0,XXX),Row2(SDP,CS5.0,YYY
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
How to display data fom MySQL DataBase-table in to JSP file by submitting... to create a viewTR.jsp file in netbeans IDE, where i have to : 1.connect to DB in MYSQL and 2.TR List:input Text Box and button. 3.In the same viewTR.jsp file, i
how to get multiple hyperlink values from a table column to another jsp file?
how to get multiple hyperlink values from a table column to another jsp file?  dear sir: this is what i'm trying to do, i have 3 JSP files. first... i copy the hyperlink value to that third jsp file "table2", or if you have
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
a jsp file which contains a textbox, name issuedescription. when user types... in textbox values in jsp file  Hi am new to java. i need to create... Solution field from database and display in the textbox of the jsp.   1
Implementing CSS and JavaScript in JSP File
Implementing CSS and JavaScript in JSP File... and JavaScript in jsp. Here we have created three main files that is cssScript.jsp, validate.js and style.css.  In "cssScript.jsp" file
Life Cycle of a Jsp Page
Life Cycle of a Jsp Page          Life of the the jsp page is just same as the servlet life cycle. After get translated the jsp file is just like
JSP Tag Libraries
JSP Tag Libraries       JSP Tag Libraries is the collection of standard tags. JSP tags are the Java components that can be used in a JSP file. JSP tag libraries allow us to make Java
Understanding Struts Action Class
Class and forward a jsp file through it.  What is Action Class?ADS... is used by the Struts Framework to forward the request to the file as per...;, which is defined in the struts-config.xml file (action mapping is show later
XML Transformation in JSP
illustrate use of XML transformation tag in JSP file. This example performs... in JSP file. In this XSL file we have called template "processuser"... XML Transformation in JSP  
jsp:include action tag
,  which inserts the file at the time when jsp page is translated... inside the directive tag. The jsp include tag is used to include the file... created a jsp file which has to be included in the other jsp file by using
JSP Include jsp
include either a static or dynamic file in a JSP file. If the file is static, its text or content is included in the calling JSP page. If the file is dynamic... JSP Include jsp   
How to Open JSP?
file is simple text file with HTML code embedded with Java Code. Since JSP... the menu bar and then browser the jsp file, select it and click on the "... editor will open the JSP file in the editor window. In the editor window you
Reading Request Information
Retrieving the data posted to a JSP file from HTML file...; Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his/her
Introduction to JSP
sun
sun  how to run one jsp file
JSF - JSP-Interview Questions
JSF  How to embedded PDF in JSF page(jsp file created
jsp - JSP-Interview Questions
jsp  hi, we have a jsp page and when we send a request the jsp file will going to execute but the server is crashed, at that time we need to stop the execution of jsp file. how can we stop the jsp file
How to include?
How to include?  How can we include a JSP file in one application to the JSP file in another application which are in the same server?? please help me out with code
coding
coding  how to write a code for searching a link in another jsp file?pl give the soln soon
jsp
jsp  write a code for jsp file generator to generate a jsp page automatically taking html page as input
use ajaxtag in Struts1.3
use ajaxtag in Struts1.3  How can use ajax tag library in jsp file in struts 1.3
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file

Ads