| Author |
another way to download
|
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
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)
|
 |
Mike Fuellbrandt
Greenhorn
Joined: Jan 17, 2002
Posts: 14
|
|
|
Take a look at the HttpServletRequest interface. getPathInfo() is probably what you're looking for.
|
 |
Brahim Bakayoko
Ranch Hand
Joined: Aug 29, 2003
Posts: 155
|
|
Nothing is stopping you of doing so. The query string is not part of the URL pattern.
|
SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Thanks alot. but can you write some lines of code because I didn't understanding what you mean.
|
 |
Mike Fuellbrandt
Greenhorn
Joined: Jan 17, 2002
Posts: 14
|
|
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.
|
 |
 |
|
|
subject: another way to download
|
|
|