This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to hide image path in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to hide image path in JSP" Watch "How to hide image path in JSP" New topic
Author

How to hide image path in JSP

Sapan Shah
Greenhorn

Joined: Jan 01, 2010
Posts: 25
Hi

I want to hide image path which we are displaying on our website i.e. any user when do right click and view source, the path should be in encrypted form.
So that whenever anyone copy the image url and copy that url in any browser the image should not display.

We display our image in following way

<img src="http://www.abc.com/3562356.jpg" width="150" height="150" ></img>

Where www.abc.com is a server in which all these .jpg files are uploaded.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

There is no way to accomplish this. If the browser can show the image, it is available to the end user.

You can make it harder to download the image, but you cannot prevent it.

(And please, don't even think of trying to do something as silly as disabling right-click.)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12753
    
    5
You can have the image resource served by a servlet and use an identifier for the image that has nothing to do with the file name.

You might encrypt the name with the session ID, thus the link would be useless after the user left the session.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I have seen people do things in that servlet like checking the referrer header, to ensure that the request is coming from the page in which the image is supposed to appear and from nowhere else.

Of course the referrer header can be faked, but it's like Bear said, you can't prevent people from accessing the image, you can only make it harder.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

You could use say a servlet to display the image or perform some weird doohickey like make an AJAX call with a HTTP header that uniquely identifies your request. But these can be faked.

you can only make it harder.


Very true


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

I strongly suspect (only because 99.99999% of the times that this question is asked this is true) that the OP wants to prevent people from saving the image to their own systems. So no matter what gyrations are used to present the image in the browser, once it's visible in the browser, the user can save the image to their system.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Bear Bibeault wrote:I strongly suspect (only because 99.99999% of the times that this question is asked this is true) that the OP wants to prevent people from saving the image to their own systems. So no matter what gyrations are used to present the image in the browser, once it's visible in the browser, the user can save the image to their system.


Not to mention proxies that could cache an image, if you are worried about image theft.

Just saying that is something to consider based on what the OP wants
Tarun Bolla
Ranch Hand

Joined: Jun 20, 2011
Posts: 89
Yeah ... Bear said it right...Once displayed in browser .. no one can stop the person from saving it...
Even if you use scripts ... one can take a screenshot and crop out the required image out of it....
 
 
subject: How to hide image path in JSP
 
Similar Threads
Problem Repainting Panel
Problem displaying images from "/"
Not able to display images
displaying images in jsp page..
get ting absolute path