aspose file tools
The moose likes Servlets and the fly likes hyperlink in a servelt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "hyperlink in a servelt" Watch "hyperlink in a servelt" New topic
Author

hyperlink in a servelt

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 472

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?


Thanks,
Sherif
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3028
    
    4

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.


Steve
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 472

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

Joined: Jan 10, 2002
Posts: 56179
    
  13

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 ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 472

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

Joined: Jan 10, 2002
Posts: 56179
    
  13

Be sure you understand why that worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hyperlink in a servelt
 
Similar Threads
JLable as hyperlink
why could not view back the attachment files
Logging in to 2 separate Log Files ?
Deplyoing a JSP page in Sun One Application server 7
How to input data from keyboard using jdeveloper 10g for a java application.