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!
Don't want to ruin the beauty of my first answer, by explaining the thing. Therefore, I decided, explanation should go here, instead.
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.
Is this not possible for some security reason? Or am I doing something wrong here?
Yes.
精彩评论