Reputation: 1296
I want to display image from my local location in computer,I am use this code for that it works fine for me,
<%@ page import="java.io.*" %>
<%@page contentType="image/gif" %>
<%
OutputStream o = response.getOutputStream();
InputStream is = new FileInputStream(new File("D:/FTP/ECG/ecg.jpg"));
byte[] buf = new byte[32 * 1024];
int nRead = 0;
while( (nRead=is.read(buf)) != -1 )
{
o.write(buf, 0, nRead);
}
o.flush();
o.close();
%>
My question is that i want to display content with it, and also other thing with it like input box and labels also.
Upvotes: 0
Views: 1658
Reputation: 901
Scriptlets = nono, code is much less readable with them. Use JSTL where you can.
To display the actualy image use html tag
<img src="D:/FTP/ECG/ecg.jpg" />
Let's assume you have a page where list of images (loaded from db) is to be displayed.
In your controller in a method that prepares the view:
ModelAndView mv = new ModelAndView("yourView");
mv.addObject("imageList",imageList);
return mv;
imageList is simply a list of filenames (List) which you loaded from the db before.
Then in your jsp you do:
<c:forEach items="${imageList}" var="path">
<img src="yourPath/${path} />
</c:forEach>
Upvotes: 0
Reputation: 6354
What you are doing here is streaming an image to the client. What you need is an HTML document which refers to this image, like:
<img src="path/to/your/jsp">
<p>Some other text</p>
Upvotes: 1