• 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

hyperlink in a servelt

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ,

I wanna show a file hyperlink in Servlet to the user , so i wrote the :
when the application runs the "file url " appears like this : " file:///c:/Program" and this not like the link i wanna so why it's not appearing the path as i wrote it , and how to fix this?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The space character is not allowed in a URL, so you have to replace them with '+' the URL-encoded form of spaces:


The File:/// will be added as a replacement for http:// on the client side.

Note that this only works when you try to visit the page from the SAME computer as the server is running for. The file being linked to will be present on the SERVER, not the CLIENT, but a file:// url will try to find a file on the CLIENT's computer. If you want to be able to access the link from other computers you would have to move the file into your web application's working directory (Web App path).

This is also a display feature, so you should be making links/displaying values in JSPs, not Servlets.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply , i tried to get the file url in the servlet by using

and displaying it throw the servlet (i know all the presentation module should be in JSPs but this is a very tiny line of code ) so i display the appeared url in "file url" is :although I'm printing the file path in the console it looks like this :

PS: what i wanna is to show a link that when you presses it this file can be downloaded
So any advice ??
[ November 01, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming the the MyWebApp folder is the context root of your web app (the folder that WEB-INF is in), then an anchor with the proper URL would be:


[ November 01, 2008: Message edited by: Bear Bibeault ]
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Assuming the the MyWebApp folder is the context root of your web app (the folder that WEB-INF is in), then an anchor with the proper URL would be:



[ November 01, 2008: Message edited by: Bear Bibeault ]


Thanks much for your help it's up and running now
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be sure you understand why that worked.
reply
    Bookmark Topic Watch Topic
  • New Topic