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 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>









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
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
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
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
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
how to get the details of username&password of mysql - JDBC
how to get the details of username&password of mysql  Hi friends, i installed mysql 5.5 on my system successfully,but the thing is i forgotten the username and password .please tell me how to get those details . Thanks
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
How can I get specific data from JSON
How can I get specific data from JSON  Hi, How can I get specific data from JSON? Thanks
Hide hyperlink using jQuery
Hide hyperlink using jQuery In this tutorial, we will discuss about how to hide hyperlink after clicking it using jQuery. In the below example , a hyperlink... for hiding link after clicking : $("a").click(function () { $(this).hide
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
How can I get specific data from JSON
How can I get specific data from JSON  Hi, How can I get specific... to parse json string. After parsing the json string into JSON object you can get... shows how you can get the user from the json: >>> import json >>>
enable hyperlink
enable hyperlink  How to enable hyperlink
How to get specific index value from int buffer.
How to get specific index value from int buffer. In this tutorial, we will discuss how  to get specific index value from int buffer. IntBuffer...; int get(int index) The get() method reads int value
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
How to get specific index value from long buffer.
How to get specific index value from long buffer. In this tutorial, we will discuss how  to get specific index value from long buffer. LongBuffer....  long get(int index) The get() method read long value
How to get specific index value from short buffer.
How to get specific index value from short buffer. In this tutorial, we will discuss how  to get specific index value from short buffer. ShortBuffer....  abstract short get( int index) The get() method
How to get specific index value from ByteBuffer in java.
How to get specific index value from ByteBuffer in java.    ... will discuss how to get value of a given index from buffer. The ByteBuffer class is a container for handling data. The get(int index) method of ByteBuffer
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
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
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
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
Connecting to Database from a hyperlink in JSP - JSP-Servlet
Connecting to Database from a hyperlink in JSP  How can I connect to database by clicking on a hyperlink in a JSP Page.Can you please give me sample code for that? Thanks, Srinivasa Rao  Hi friend, insert code
eclips hyperlink - JSP-Servlet
eclips hyperlink  In my myeclipse if hyperlink is provided in any application , it's not working when I deploy it. I also use net at my PC, is there any problem due to IP Address
Item renderer in flex
Item renderer in flex  Hi..... How does item renderer work? How do I add item renderer at runtime? Please me the right answer so i cam implement this in my apps. Thanks  Ans: The base class for Spark item
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
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
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
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
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
delete an item from database
delete an item from database  how to delete an item from the database using jsp
customer details
customer details  write a java code to enter n number of persons details(name,address,phone number) in a array list. Also consider exceptional cases like entering integer in name,character in phone number. use try,catch ,throw
APLIANCE DETAILS
APLIANCE DETAILS  I have created a package named ApplianceDetails that contains the Appliance class. Now I want to create a class named NewAppliance that stores the details of the newly launched appliances.I used the following
ModuleNotFoundError: No module named 'item'
ModuleNotFoundError: No module named 'item'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'item' How to remove the ModuleNotFoundError: No module named 'item' error
hyperlink the pages with diff-2 actions struts - Struts
hyperlink the pages with actions struts  How to make a hyperlink in struts?  a href = "login.do" > Login </a> ... would definitely get your answers. so first learn ithttp://www.roseindia.net
Item renderer in flex
Item renderer in flex  Hi...... please tell me about How to create item renderers in flex? give an example for that Thanks
Retrieve data by clicking a link
Retrieve data by clicking a link  In a page there are 5 links.Every link has a hidden value. According to that hidden value data should be retrieved from the database and data should be displayed in a new page.How to do it?Please
Creating Hyperlink using GWT
Creating Hyperlink using GWT       This example describes the Basics for building the Hyperlink using GWT. The steps involved in Building the Hyperlink are described below
Use of Hyperlink in Swing - Swing AWT
Use of Hyperlink in Swing  Hi, We are developing the UI using the Java Swing and I have to create Hyperlink in the JTable cell so that if the user click on the Hyperlink it will open other window/screen/panel. My Question

Ads