Reputation: 195
I want to get a photo in my jsp pages. I implemented the servlet in this way (in doGet method):
{...
byte[] imageData = u.getFoto();
response.setContentType("image/jpg");
response.getOutputStream().write(imageData);
..}
where u
is a User
type.
My question is: how can I set the src path in my jsp page to retrieve the image from Servlet??
Upvotes: 0
Views: 1253
Reputation: 7848
You would specify the mount point in your web.xml
, with something like this:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/img/myservlet</url-pattern>
</servlet-mapping>
That will take the servlet named MyServlet
and mount it to /img/myservlet
. Then, in your jsp you would just use an img
tag pointing to the url-pattern
specified above.
<img src="/img/myservlet" />
Note: if your webapp is not mounted to /, you will also need to specify the contextPath for the application in the path.
Upvotes: 3