File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Jsp and images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp and images" Watch "Jsp and images" New topic

Jsp and images

Sabarish Jaganathan

Joined: Apr 05, 2013
Posts: 14
hi to all i had been insert image name (with file format) in to database using jsp i need to retrive the name of the image in the hyperlink so if admin clicks on the link image will be displayed but i couldn't able display it with using <img> src tag how to display it please any body help me i will upload my code below

code for retriving image

<%@page import="java.sql.ResultSet"%>
<%@ page import="java.sql.*" %>
<title>View Image Page</title>
<table width="100%" border="0">
<%!Statement st=null;
Connection con=null;
ResultSet rs=null;
rs=st.executeQuery("select id from num");
<table width="70%" height="160" border="1" align="center">
<!-- Mention Directory where your images has been saved-->
<td> <img src = "C:/Users/JAGANATHAN/Documents/NetBeansProjects/visuvam project/UploadedFiles/<%=rs.getString("id") %>" width="115" height="128" <a href="retrive.jsp?Image=<%=rs.getString("id")%>"></a> </td>
catch(Exception e)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Some important questions you need to answer:
  • Why are you using a file path for the image? That will never work anywhere except for your own PC.
  • Why is there Java code in your JSP? That's an obsolete practice from over 12 years ago.
  • Is more than one person going to use this web app? Because the way the page is written, it will break if more than one person acesses it.

  • For the above:

    The path to the image must be a URL to resolves that the image file (or any resource that will serve the image data). It cannot be a file path.

    Any Java code needed to get data for the page must be in the page controller or classes that the controller calls. It should not be in the JSP. Ever. You should only be using the JSTL and EL on the JSP page.

    Even if you choose to use Java scriptlets on the page (and you should not) the use of scriptlet declarations makes the page non-thread-safe. Never use declarations on a JSP page. This problem solves itself if you remove all Java code from the JSP.

    [Asking smart questions] [About Bear] [Books by Bear]
    I agree. Here's the link:
    subject: Jsp and images
    It's not a secret anymore!