• Post Reply Bookmark Topic Watch Topic
  • New Topic

client code downloading from Servlet  RSS feed

 
Muni K Reddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I was going through HF Servlets and JSP's and was trying out the following.

Web.xml :


All I would like the above code to do is that while the file names "htmlconverter.jar" is being downloaded I would like a JSP in the background to give a description of the file. However, when I run this code two unexpected things are happening.

  • The file which is being downloaded is named "TestServlet.do".
  • The JSP is never dispalyed.


  • Could someone please let me know where I am going wrong??
    Many Thanks
     
    Alok Kushwah
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Muni,

    To give the name of file which you sending as response, use response's Content-Disposition header.

    res.setContentType("application/x-download");
    res.setHeader("Content-Disposition", "attachment; filename=" + filename);

    However you should not forward the same request to other resource. You should commit the response by flushing and closing connection; otherwise client will not receive the right content. You are accepting that request and sending 200 OK status to client and sending content of your jar file. Do you want to append the content of other resource in the same response by forwarding same request to other resource? I don�t think so.

    Regards
    Alok S Kushwah
     
    Alok Kushwah
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Do you want to launch an application using classes in application.jar? If yes, what is your strategy to launch it? Are you using applets? Have you signed the jar? Have you considered network class loader? I think, this is the path you need to go.

    Best of luck
    Alok S kushwah
     
    Muni K Reddy
    Ranch Hand
    Posts: 74
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Alok Kushwah:
    Do you want to launch an application using classes in application.jar? If yes, what is your strategy to launch it? Are you using applets? Have you signed the jar? Have you considered network class loader? I think, this is the path you need to go.

    Best of luck
    Alok S kushwah


    Thanks Alok,
    I will need to work on the few things which you have just mentioned.
    For starters, What if I have a JSP page just like say Java download page which has the following:
  • JDK Download of Linux : JDK_linux.jar
  • JDK Dowload for Windows: JDK_Win.exe

  • Depending on your OS you would click one of the two items, which would lead you to another page describing the contents and whether download is activated. How do I achieve this?
    [ August 28, 2007: Message edited by: Muni K Reddy ]
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Muni K Reddy:
    Depending on your OS you would click one of the two items, which would lead you to another page describing the contents and whether download is activated. How do I achieve this?


    The User-Agent request header will contain information about the browser and (possibly the OS).

    If I were doing this I would write code that parses this header, attempts to ascertain the OS, and either shows the proper download, if the OS can be determined or asks the user to choose the proper OS if not.
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!