• 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

another way to download

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I have a servlet that download pdf books.
this servlet takes the name of the book as a parameter like:
http://domain/download?name=ebook.pdf
now, I want to develope a servlet that has the following url pattern:
/*.pdf
so I can write:
http://domain/ebook.pdf
but the problem is, how the servlet could know the name of the book to download (the site could have many pdfs so I can't hard code the book's name in the servlet)
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the HttpServletRequest interface. getPathInfo() is probably what you're looking for.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing is stopping you of doing so.
The query string is not part of the URL pattern.
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot.
but can you write some lines of code because I didn't understanding what you mean.
 
Mike Fuellbrandt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's two ways to attack this one I think...

First, set up a servlet-mapping for /download/* to point to your servlet.

When you call http://yourDomain/download/ebook.pdf, everything after the uri part 'download' will be returned by a call to request.getPathInfo() (i.e. /ebook.pdf). Strip off the preceding slash and you have your file name. The advantage here is you can include some directory structure to keep the pdf directory clean and organized.
i.e. http://yourDomain/download/manuals/java/user_guide.pdf -> %PDF_ROOT%/manuals/java/user_guide.pdf

The disadvantage would be that you are exposing the directory structure which may be a security hazard for you.


The second way would be to map *.pdf in the servlet-mapping to your servlet. Then you can call http://yourDomain/downloads/ebook.pdf and request.getServletPath() will return /downloads/ebook.pdf.
 
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic