views:

134

answers:

2

Hi, I am trying out a simple implementation of a URL shortener such as tinyurl.com or bit.ly. Currently I do a response.sendRedirect(targetURL) in my servlet - which works fine for http/ftp target URLs.

However, I'm having problems redirecting to targets such as file:///c:/temp (where c:\temp is of course on the local/client system).

Typing file:///c:/temp on the Firefox address bar works, but a redirection from a server seems to do nothing.

Is this not possible for some security reason? Or am I doing something wrong here?

Thanks in advance!

+1  A: 

Is this not possible for some security reason? Or am I doing something wrong here?

Yes.

Adeel Ansari
This is the neatest accepted answer I ever seen, nice :
Jay Zeng
Sorry Jay. The boss asked me to accept the second :)
Raj
+1  A: 

Don't want to ruin the beauty of my first answer, by explaining the thing. Thus, decided that that should go here.

Well, how can you think to access a local drive of your client, in the first place. Its a security concern, indeed. You don't have access to your client's filesystem, just like that.

It seems that you have no requirement to do that. If you have to, for some weired reason, then you can think of a signed applet or something, I believe.

As far as your confusion goes, that it is working on your firefox. It is because you have the access to your own machine and URL is just fine for firefox to understand. However, inside a servlet, you can't just do that. Read the docs for sendRedirect(), it says

If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

Adeel Ansari
Thanks - that makes sense.However, in IE - redirection works for 'some' targets. Redirects to local disk 'C:\foo.doc' don't seem to work, but 'D:\foo.doc' does - where 'D' is a network drive.
Raj
Where `D` is network drive and it is mounted. Indeed, that would work, why it should not. Not sure about the problem accessing your `C` drive using IE. What message are you getting, BTW?
Adeel Ansari
The 'Internet Explorer cannot display the webpage' error
Raj
Are you sure, you have foo.doc in your `C` drive? If yes, then there must be something about windows primary partition or NTFS partition or something like that. Not sure, can't say anything for sure. Never encountered this, as I don't have Windows. ;)
Adeel Ansari