jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Image from Website 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 » Java » Servlets
Bookmark "Image from Website" Watch "Image from Website" New topic
Author

Image from Website

Shiaber Shaam
Ranch Hand

Joined: Jun 16, 2006
Posts: 252
Hi

Am writing a servlet ti return the image from a website. The same servlet is working for a local path and its not working if i give a web path. Please advise.

Thanks,


$Hi/\bEr
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
if you are using getResource this will only work within your webapp or other webapps deployed in the same container.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

The URL is likely malformed. Without more details, that's pretty much all that can be guessed.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shiaber Shaam
Ranch Hand

Joined: Jun 16, 2006
Posts: 252
URL url = new URL(request.getParameter("src"));
File file = new File(url.getFile());

this is how i am accessing, request.getParameter("src") being a web url for a jpg.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
What kind of exception are you getting? are you sure you have access to that resource?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

Shiaber Shaam wrote:URL url = new URL(request.getParameter("src"));
File file = new File(url.getFile());

this is how i am accessing, request.getParameter("src") being a web url for a jpg.

That tells us nothing. Is that URL valid for the image?
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Can you show us the contents of the 'src' parameter?

Is this the location of a file on the client machine or on the server machine?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image from Website
 
Similar Threads
In need of help urgently with servlets
servlet basics
Execution difference on Application Server
Displaying an image in a servlet
get image from database