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



Home Answers Viewqa Servlet-Interview-Questions download code using servlet

Have Programming Question? Ask it here!
 
 
 


rayappa
download code using servlet
1 Answer(s)      6 years and a month ago
Posted in : Servlet Interview Questions



Advertisement
View Answers

August 9, 2012 at 11:42 AM


import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException;

import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

public class DownloadServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { static final long serialVersionUID = 1L; private static final int BUFSIZE = 4096; private String filePath;

public void init() {
    // the file data.xls is under web application folder
    filePath = getServletContext().getRealPath("") + File.separator + "data.xls";
}

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    File file = new File(filePath);
    int length   = 0;
    ServletOutputStream outStream = response.getOutputStream();
    ServletContext context  = getServletConfig().getServletContext();
    String mimetype = context.getMimeType(filePath);

    // sets response content type
    if (mimetype == null) {
        mimetype = "application/octet-stream";
    }
    response.setContentType(mimetype);
    response.setContentLength((int)file.length());
    String fileName = (new File(filePath)).getName();

    // sets HTTP header
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

    byte[] byteBuffer = new byte[BUFSIZE];
    DataInputStream in = new DataInputStream(new FileInputStream(file));

    // reads the file's bytes and writes them to the response stream
    while ((in != null) && ((length = in.read(byteBuffer)) != -1))
    {
        outStream.write(byteBuffer,0,length);
    }

    in.close();
    outStream.close();
}

}



Related Tutorials/Questions & Answers:
download code using servlet - Servlet Interview Questions
download code using servlet  How to download a file from web to our system using Servlet
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
Advertisements
how to create xls file and give download option using jsp/servlet?
how to create xls file and give download option using jsp/servlet?  Hi, how to create file and give download option to user,so that the user can save the file on defined path
upload and download files from ftp server using servlet - Ajax
for upload and download files from ftp server using servlet and how to use servlet for these applications.I have send my code to you previous time...upload and download files from ftp server using servlet  Hi,Sir
java/jsp code to download a video
java/jsp code to download a video  how can i download a video using jsp/servlet
download code from database
download code from database  how to download files from database
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
php download file code
php download file code  PHP code to download the files from the remote server
download - JSP-Servlet
download  here is the code in servlet for download a file. while... help me out its urgent!! code servlet: /* * To change this template...(); System.out.println("inside download servlet"); BufferedInputStream
code for password strength using jsp-servlet
code for password strength using jsp-servlet  hi.............. plz help me to give code for password strength using jsp-servlet for implementation in my project as soon as possible because i want to show this functionality in my
Download LINK - JSP-Servlet
Download LINK  sorry i am the new1 to java. I am learning and doing the project, can you please send me the complete code. So that i can understand easily. i want the code like by Clicking DOWNLOAD button the SAVE as dialog box
Download Button - JSP-Servlet
Download Button  HI friends, This is my maiden question.... And i want the Bank customers to DOWNLOAD the mini statement. Can any one help me how to implement the download button so that on clicking that the mini
HTML code to servlet to database using jdbc
HTML code to servlet to database using jdbc  pls send me the code related to the title   Hi Friend, Try the following code: 1)form.html: <html> <form method="post" action="http://localhost:8080/examples/Data
How to download files from server to local disk using ZIP format in JSP page - JSP-Servlet
How to download files from server to local disk using ZIP format in JSP page  hi i have an application to upload and download multiple files. As i can upload multiple files .now i have to download all uploaded files on local
download image using url in jsp
download image using url in jsp  how to download image using url in jsp
How to download JDK source code?
How to download JDK source code? This articles explains you how you can download the source code of JDK. You will learn how to download JDK source code... to download JDK source code? JDK installer is packaged with the binary of the JDK
upload and download files - JSP-Servlet
upload and download files  HI!! how can I upload (more than 1 file) and download the files using jsp. Is any lib folders to be pasted? kindly... and download files in JSP visit to : http://www.roseindia.net/jsp/file_upload
JSP file download - JSP-Servlet
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 on the link it is asking open or save. Upto this is fine..... I want to download
org.jfree package download - JSP-Servlet
org.jfree package download  I saw a code in roseindia but that code requires a package "org.jfree.chart.*" and "org.jfree.ui.*" Please give me the packages .  Hi friend, Plz download the jar files
Upload and Download in JSP - JSP-Servlet
Upload and Download in JSP  Respected Sir/Madam, I am... files and similarly when the user clicks the download option, he must be able to do so.. I am Using a table named file_tbl (MS-Access) Also if opossible
Upload and download file - JSP-Servlet
Upload and download file  What is JSP code to upload and download a document in a web page?  Hi Friend, Try the following code to upload............ Now to download the word document file, try the following code
download java source code for offline referral
download java source code for offline referral   how can i download complete java tutorial from rose india so that i can refer them offline
code to upload and download a file - Java Magazine
code to upload and download a file  Is their any code to upload a file and download a file from databse, My requirement is how can i store two... user send one a.doc file to x ,he has to download his a.doc another user sends
java code to upload and download a file - Java Beginners
java code to upload and download a file  Is their any java code to upload a file and download a file from databse, My requirement is how can i..., one user send one a.doc file to x ,he has to download his a.doc another
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
File Upload And download JSP Urgent - JSP-Servlet
Ragavendran, i am sending code of file download in jsp. Plz implement this code...File Upload And download JSP Urgent  Respected Sir/Madam, I... Download in JSP.. In the Admin window, There must be "Upload" provision where admin
Source Code for Implementing Search Feature in JSP using Java action/Servlet - JSP-Servlet
Source Code for Implementing Search Feature in JSP using Java action/Servlet  How do I write the source code to implement search feature in JSP using Java action/servlet? My query is: SELECT @rownum:=@rownum+1 'rownum', X
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig
download
download  how to download the file in server using php code: "<form method="post" action=""> enter the folder name<input type="text" name... the wrong foldername"; end1: } ?> </form>`print("code sample
To download a website from a given url. - JSP-Servlet
To download a website from a given url.  write a program to download a website from a given URL.it must download all the pages from that website.it should take the depth of retrieval from user input.all the files pages must
servlet code
servlet code  how to implement insert update n delete in one servlet in net beans   If you want to perform insert, update and delete functions in the same servlet, then please visit the following links: http
Download
Download JDK  How to Download the latest Version of JDK?   Download OST to PST converter from: http://www.osttopst.info
Download.
Download.  I need a swing program to download a file from the server
Capture browser file download event - JSP-Servlet
Capture browser file download event  Hi, I appreciate your help and thaanks for that.But my question was when filedownload dialog box comes in browser,how we can come to know that user has clicked on Open,save or cancel button
servlet code - JSP-Servlet
servlet code  Create a servlet to develop a login application with javascript clientside validations and serverside validations
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig   Hi Friend, Please visit the following link: http://roseindia.net/jsp/bank.shtml Thanks
Download Search Engine Code its free and Search engine is developed in Servlets
Installation Instruction Download...; Compile search.java file and install the servlet on you...:serverport/servlet/search in your browser. By now your search
servlet code - JSP-Servlet
servlet code  how to implement paging or pagination in java code using servlets.  Hi Friend, Try the following code: import java.io.... code, we have used following database table: CREATE TABLE `student
Download full code of JSF, Spring and Hibernate based Registration program
Download full code of JSF, Spring and Hibernate based Registration program...; From this page you can download the source code of the application. Downloading code Click here to download the code of the application. Extracting
Download dynamic link files to local directory - java code
Download dynamic link files to local directory - java code  Hi, I found a code that downloads static links but not dynamic link files.can anyone give a solution for downloading dynamic link files? Thanks in advance
How to download and save a file from Internet using Java?
How to download and save a file from Internet using Java?  How to download and save a file from Internet using Java
Source Code for Implementing Search Feature in JSF/JSP using Servlet - Java Beginners
Source Code for Implementing Search Feature in JSF/JSP using Servlet  How do I write the source code to implement search feature in JSF/JSP using Servlet?? Please advice using the example data below:- Thank You!! Employee
java servlet code - Servlet Interview Questions
java servlet code  iam doing a project in java, preparation of on line examination in that how to prepare a question paper using servlet code
Source Code for Implementing Search Feature in JSP using Java Action/Servlet - JSP-Interview Questions
Source Code for Implementing Search Feature in JSP using Java Action/Servlet  How do I write the source code to implement search feature in JSP using Java action/servlet? (java action is the priority, but servlet is OK) My
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
Re:number of Files download problem in jsp - JSP-Servlet
Re:number of Files download problem in jsp  I write code for single file downloading , but I want to download number of files at same time , means I want stored number of files in one temp zip file then it download it. please
code - Servlet Interview Questions
by the servlet container. The status code of the response always should...code  servlet service method along with an example code  Hi Friend, Servlet service() method: Once the servlet starts getting
Code - JSP-Servlet
Code  Using servlet,JSP,JDBC and XML create a Web application for a courrier company to provide online help in tracking the delivery status of items
servlet code to update password?
servlet code to update password?  Create a servlet page which helps the user to update his password. The user should give the username,old password... users.then Store it into a table. please tell me the code for the above question
atm code in servlet& jsp
atm code in servlet& jsp  pls send me the code of ATM project in servlet jsp . my requirements are first of all an user login window open then balance enquiry, withdraw of money, money transfer, then log out. pls send as early
Advertisements
 

 

 

DMCA.com