91-9990449935 0120-4256464 |
Example of downloading file from the server in servletFor downloading a file from the server, here is the simple example. I am supposing you have home.jsp file in E drive that you want to download. If there is any jar or zip file, you can direct provide a link to that file. So there is no need to write the program to download. But if there is any java file or jsp file etc, you need to create a program to download that file. Example of downloading file from the server in servletIn this example, we are creating three files:
index.html This file provides a link to download the file. DownloadServlet.java This is the servlet file that reads the content of the file and writes it into the stream to send as a response. For this purpose, we need to inform the server, so we are setting the content type as APPLICATION/OCTET-STREAM . web.xml file This configuration file provides informations to the server about the servlet.
download this example (developed without IDE)
download this example (developed using Myeclipse IDE) download this example (developed using Eclipse IDE) download this example (developed using Netbeans IDE) |