0

i want to display image at browser with help of given code

images.jsp

<%@ page contentType="text/html"%> <%@ pageimport="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" %> <html> <body><center><table border="2"> <%DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("\\file1.XML"); NodeList pic1= doc.getElementsByTagName("pic1"); NodeList pic2= doc.getElementsByTagName("pic2"); %> <tr><td> <img border="2" src=<%= pic1.item(0).getFirstChild().getNodeValue() %> width="137" height="140"></td> <td> <img border="2" src=<%= pic2.item(0).getFirstChild().getNodeValue() %> width="137" height="140"> </td> </tr> </table> </center> </body> </html> 

file1.xml

<?xml version="1.0" encoding="UTF-8"?> <images> <pic1>BULDHANA.jpg</pic1> <pic2>BULDHANA.jpg</pic2> </images> 

but it is not display images. Where is the problem. How can i resolve it???

3
  • How does the generated HTML look like? Are the image paths correct? Commented Feb 24, 2011 at 9:09
  • You have not posted the contents of file1.xml. Did you try wrapping the img src with double quotes? Commented Feb 24, 2011 at 9:09
  • <?xml version="1.0" encoding="UTF-8"?> <images> <pic1>BULDHANA.jpg</pic1> <pic2>BULDHANA.jpg</pic2> </images> this is the code for file1.xml Commented Feb 24, 2011 at 9:10

1 Answer 1

1

Check HTML rendered on browser check for img tag whats its src attribute?? , and what it should be ??

Update:

Your dir structure should be like this

jsp file at

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\SampleApp\1.jsp 

image file at

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\SampleApp\images\1.jpg 

in my browser address bar

http://localhost:8080/SampleApp/1.jsp 

HTML code

<img src="images/1.jpg"/> 
Sign up to request clarification or add additional context in comments.

23 Comments

@Felix It is answer to her question actually.
@Jigar Joshi - org.life.java: Not really. You are asking two questions yourself. Now if the OP founds out that the paths are incorrect, what should he do? You are just telling him what he should do to find out what could be wrong, but not how to solve the problem (displaying images).
i am placed file1.xml inside bin and images inside webapps\jsp-examples. It is not showing images.Where i have to place images???
@neha soni: First you have to show us how the generated HTML looks like. Are the image sources correct?
just add <img border="2" src=/images/<%= pic2.item(0).getFirstChild().getNodeValue() %>
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.