
sir, I am developing a shopping site, following is my problem definition: I have a search item button, if I click on that button it lists all items with item name and corresponding image with a hyperlink on it from the database to a jsp page.
-If I click on the image or item name I should get total datails from the database of that particular item which I clicked. How should I perform this? Thanks in advance

1)listitem.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<HTML>
<table border="1">
<tr><th>Items</th><th>Image</th></tr>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement stmt=con.createStatement();
String strQuery = "select * from items";
ResultSet rs = stmt.executeQuery(strQuery);
while(rs.next()){
%>
<tr>
<td><%=rs.getString("item")%></td>
<td>
<a href="info.jsp?imgid=<%=rs.getInt(1)%>">
<img src="items.jsp?imgid=<%=rs.getInt(1)%>" width="50" height="50">
</a></td>
</tr>
<%
}
rs.close();
con.close();
stmt.close();
}
catch(Exception e)
{
e.getMessage();
}
%>
</table>
</HTML>
2)items.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<%
int id = Integer.parseInt(request.getParameter("imgid"));
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
String strQuery = "select image from items where id="+id;
ResultSet rs = st.executeQuery(strQuery);
String imgLen="";
if(rs.next()){
imgLen = rs.getString(1);
}
rs = st.executeQuery(strQuery);
if(rs.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
st.close();
response.reset();
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}
catch (Exception e){
e.printStackTrace();
}
%>
3)info.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<table>
<%
int id = Integer.parseInt(request.getParameter("imgid"));
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
String strQuery = "select * from items where id="+id;
ResultSet rs = st.executeQuery(strQuery);
if(rs.next()){
%>
<tr><td>Item:</td><td><input type="text" value="<%=rs.getString("item")%>"></td></tr>
<tr><td>Price:</td><td><input type="text" value="<%=rs.getDouble("price")%>"></td></tr>
<tr><td>Information:</td><td><textarea cols="15" rows="5"><%=rs.getString("information")%>

Modify info.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<table>
<%
int id = Integer.parseInt(request.getParameter("imgid"));
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
String strQuery = "select * from items where id="+id;
ResultSet rs = st.executeQuery(strQuery);
if(rs.next()){
%>
<tr><td>Item:</td><td><input type="text" value="<%=rs.getString("item")%>"></td></tr>
<tr><td>Price:</td><td><input type="text" value="<%=rs.getDouble("price")%>"></td></tr>
<tr><td>Information:</td><td><textarea cols="15" rows="5"><%=rs.getString("information")%></textarea></td></tr>
<%
}
}
catch(Exception e){
System.out.println(e);
}
%>
</table>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.