• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet code to download the JAR doubt

 
Gopi G
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a doubt in HFSJ page no:129(Servlet code to download the JAR). In the sample servlet code they were used to get the jar file like



Can you please tell me what is purpose of ServletContext in the particular servlet class. Why we can't use response object to get the bookcode.jar in this class.

Thanks in advance.
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gopi,

There are two steps: the ServletContext is used to fetch the resource from the file system on the server, and subsequently that resource is written as a response that will be sent back to the client.

Seen from a class perspective it's more logical if the ServletContext has the responsibility of knowing how to retrieve things in the web application's environment. A response has other responsibilities. That's why I guess the getResourceAsStream() method is available in ServletContext and not in the HttpResponse class.

Hope this helps,

Gian
 
Gopi G
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.. it's ok now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic