Reputation: 586
I have a java webservice (jaxws /jersey) and want it to display an image on the firstpage when I visit the webservice using the browser.
My @GET Method which's sending the html-code for the first page is as follows:
@GET
@Produces(MediaType.TEXT_HTML)
public String getHTMLSite(){
String message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"+
"<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"de-DE\">" +
"<div style=\"padding-left:20px; height:200px; width:800px; font-size:20px;\">" +
"<p>" +
"<h1 style=\"color:#313e7d\">" +
"Hello World. This is a Webservice URL" +
"</h1>" +
"</p>"+
"<img src=\"/images/img_logo.gif\" height=\"51\" width=\"537\"/>"+
"</div>"+
"</html>";
return message;
}
Everything is working fine except the image
<img src=\"/images/img_logo.gif\" height=\"51\" width=\"537\"/>
has not been found.
I moved the image into the WebContent / images/ directory.
What am I doing wrong?
Upvotes: 0
Views: 316
Reputation: 10962
Since you've got your servlet-mapping set to /*
Jersey is going to intercept all those requests to static resources and not know what to do with them. You could:
Move the location of your servlet-mapping to /api/*
or something similar. This will resolve the static resource issue but will move the end point of all your REST calls.
Switch to the Jersey filter as described in this answer: Jersey /* servlet mapping causes 404 error for static resources
Upvotes: 1