• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jsp and images

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.*" %>
<html>
<head>
<title>View Image Page</title>
</head>
<body>
<table width="100%" border="0">
<%!Statement st=null;
Connection con=null;
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vishvum");
st=con.createStatement();
ResultSet rs=null;
try
{
rs=st.executeQuery("select id from num");
while(rs.next())
{
%>
<table width="70%" height="160" border="1" align="center">
<tr>
<!-- 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>
</tr>
</table>
<%
}
}
catch(Exception e)
{
out.print(""+e.getMessage());
}
%>
</table>
</body>
</html>
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic