This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image from Website

 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using getResource this will only work within your webapp or other webapps deployed in the same container.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL is likely malformed. Without more details, that's pretty much all that can be guessed.
 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of exception are you getting? are you sure you have access to that resource?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic