Get specific item details by clicking on hyperlink

Ads
 

Get specific item details by clicking on hyperlink

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

View Answers

April 8, 2011 at 5:31 PM

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")%>

April 8, 2011 at 5:32 PM

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>

Ads









Related Tutorials/Questions & Answers:
Get specific item details by clicking on hyperlink
Get specific item details by clicking on hyperlink  sir, I am developing a shopping site, following is my problem definition: I have a search item... on the image or item name I should get total datails from the database
storing details in database on clicking submit button - JSP-Servlet
storing details in database on clicking submit button  I am using JSP... 'Name' and 'ID'.I want to store the details of these two fields in the MYSQL database on clicking submit button. I am unable to do this.Can u tell me how to code
Advertisements
how to get multiple hyperlink values from a table column to another jsp file?
show the specific details from that hyperlink which was clicked. there are 3...how to get multiple hyperlink values from a table column to another jsp file... file named "dbtable" will get the parameter from "index" and search
Write a program to get student details and store in a database
Write a program to get student details and store in a database  Write a program to get student details and store in a database
Set Date Parameter to get specific value
Set Date Parameter to get specific value  How to set the date parameter or fetch a specific data records based on date? For example fetching the two or three months old records
get details of employee after enter the emp_id
get details of employee after enter the emp_id  how to get employee details after entered the emp_id from database after that we have three more option add new,modify and delet employee   Please visit the following
get details of employee after enter the emp_id
get details of employee after enter the emp_id  how to get employee details after entered the emp_id from database after that we have three more option add new,modify and delet employee   Please visit the following
hyperlink
hyperlink  I have a .xls file and i want the code to open this .xls file in read only mode when i click on a hyperlink,it should not not be editable,please send me the code
Hyperlink
Hyperlink  The excel file is not opening in read only mode ,it is editable,actually i need to open it in read only mode by clicking on link.please help me
Java JComboBox Get Selected Item Value
Java JComboBox Get Selected Item Value In this section we will discuss about how to get the selected item value form JComboBox. javax.swing.JComboBox... example into which I shall get the combo box selected item value and stored
JDBC: Get Column Details Example
JDBC: Get Column Details Example In this tutorial, we are describing how to get column details of a table using JDBC API. Get Column details... table. You can also put conditions to get column details by using LIKE/WHERE
I am getting error.How can i get details
I am getting error.How can i get details  Exception in thread "main" java.sql.SQLException: Listener refused the connecti n with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect
enable hyperlink
enable hyperlink  How to enable hyperlink
use data from database as hyperlink and pass the data in the hyperlink
use data from database as hyperlink and pass the data in the hyperlink  Hi Friends, I am using the data from database as hyperlink and pass the data as a parameter in the hyperlink to a servlet page. By using display table
ModuleNotFoundError: No module named 'hyperlink'
ModuleNotFoundError: No module named 'hyperlink'  Hi, My Python... 'hyperlink' How to remove the ModuleNotFoundError: No module named 'hyperlink' error? Thanks   Hi, In your python environment you
Hyperlink on UILabel iPhone SDK
Hyperlink on UILabel iPhone SDK  Hi, I wanted to set a hyperlink on UILabel in my iPhone application. Can anyone suggest me how to do it? Thanks
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
item lookup
item lookup  I need to create a lookup box in a grid that searches and filters at the same time. Upon selection the item with its price should be displayed. The control would then position below the first selection, so
ModuleNotFoundError: No module named 'clicking'
ModuleNotFoundError: No module named 'clicking'  Hi, My Python... 'clicking' How to remove the ModuleNotFoundError: No module named 'clicking... to install padas library. You can install clicking python with following
Call a servlet on click of hyperlink
Call a servlet on click of hyperlink  Call a servlet on click of hyperlink   . request.getContextPath() is used to return...; </head> <body> <h2>Click on bellow hyperlink
ModuleNotFoundError: No module named 'hyperlink-extractor'
ModuleNotFoundError: No module named 'hyperlink-extractor'  Hi, My... named 'hyperlink-extractor' How to remove the ModuleNotFoundError: No module named 'hyperlink-extractor' error? Thanks   Hi
student details
student details  create an application for details of 1st to 5th standard students by using loops and scanner
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
return item in jquery
return item in jquery  How to return items/variables in JQuery?   See the code below to find out how to return an Item in Jquery: function findItem() { var item; while(if_item_not_found) { // search
scjp details
scjp details  SCJP fees details abou scjp? What are the best books for preparing to scjp? How many time scjp exam's are conducted for one year
student details
student details  hi sir/madam i have a doubt in PHP how to insert student details using mysql with php..   Have a look at the following link: PHP Mysql insert
get
get ( ) Method in PHP  what is get method in PHP   Please visit the following link: http://www.roseindia.net/php/php-Get-Post.shtml

Ads