-1

I am returning text/html(MediaType.TEXT_HTML) from REST web service which I want to show in browser.

Return string from web Service Method=<html> <body background=\"WEB-INF\\DSCN0651.JPG\"> <h1>Hello World!!!</h1><a href="http://www.w3schools.com">Visit W3Schools.com!</a> <audio autoplay><source src=\"WEB-INF\\Coolest_Sms_All_Time.mp3\" type="audio/mpeg"</audio> </body></html>

  1. The problem I am facing is the background = DSCN0651.JPG is not rendered in browser
  2. The audio autoplay is not working as I am not able to hear sound in browser.

Though I am only able to see Hello World!!! and link www.w3schools.com! in browser after REST call.

I checked the deployment area both image and mp3 are deployed fine under WEB-INF folder I am using IE/chrome browser to make a call to my WebService get method.

Please let me know what I am doing wrong.

Blaisorblade
  • 6,438
  • 1
  • 43
  • 76

1 Answers1

0

To link images or audio (or whatever resource), you need to give a relative URL which the client browser can understand, by asking the server for that resource. If you have a webpage like the above at URL http://example.com/foo/bar, the browser will try to look up http://example.com/foo/bar/WEB-INF\DSCN0651.JPG, but that's an invalid URL. I suggest you check that by trying out the real URL yourself, and by seeing with Developer tools what the browser does with your page.

That URL is invalid at least because it uses a backward slash \ instead of a forward slash /. That's wrong in URLs. Actually, what you're showing uses \" and \\, but those should appear only when you embed them as a string in source code, to represent respectively " and \. You might want to inspect the output to ensure that's correct.

Moreover, that URL contains WEB-INF. I assume you're using a Java application server. However, the content of the WEB-INF folder is handled specially by Java application servers — in fact, resources there are not accessible to the public! So you should probably move them elsewhere and update the path (the right place depends on what you're exactly doing). Probably moving them up, outside of WEB-INF, and updating the URLs already works.

Community
  • 1
  • 1
Blaisorblade
  • 6,438
  • 1
  • 43
  • 76
  • Thank you Blaisorblade. Your answer helped me to a lot to understand the relative paths in URL and what Path I should use in html for resources. I have corrected the path of resources so that something like http://example.com/foo/bar/resources can be found by browser. – user1445322 Aug 24 '14 at 09:31
  • @user1445322, please feel free to say "thank you" by upvoting/accepting my answer :-) – Blaisorblade Aug 24 '14 at 14:42