• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

client code downloading from Servlet

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
     
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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 ]
     
    Sheriff
    Posts: 13411
    Firefox Browser VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic