• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hyperlink in a servelt

 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure you understand why that worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic