File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jar file download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jar file download" Watch "jar file download" New topic

jar file download

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 361
I have taken the following code from HFSJ that is used for downloading jar file.When the above servlet is called,the file is downloaded with name InputOutputStream. Is it possible that when the download starts, it is done with extension jar(without myself explicitly specify it during the download).

public class InputOutputStream extends HttpServlet {

public void init(ServletConfig config)throws ServletException{

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

InputStream is = getServletContext().getResourceAsStream("/archive.jar");

int iRead=0;
byte b[] = new byte[1024];

OutputStream os = res.getOutputStream();

while( ( ) != -1)


}//end of doGet

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);

SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Anand Wadhwani
Ranch Hand

Joined: Mar 21, 2005
Posts: 151
Put the following line immediately after setContentType():

This line will make the browser aware of the name to use for downloading the stram. Therefore the browser will display the download dialog box with the given name 'Archive.jar' by default. Hope this helps.
[ June 17, 2005: Message edited by: Anand Wadhwani ]

SCWCD 1.4<br />---------------------<br />Ability is what you're capable of. <br />Motivation determines what you do. <br />Attitude determines how well you do it.<br />---------------------
Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 361
Hi Anand,
thnx. It is woking fine.
I agree. Here's the link:
subject: jar file download
It's not a secret anymore!