aspose file tools*
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
Author

Jsp and images

Sabarish Jaganathan
Greenhorn

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.*" %>
<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>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

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] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Jsp and images