Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Get specific item details by clicking on hyperlink
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gautamshetkar
Get specific item details by clicking on hyperlink
2 Answer(s)      3 years and 9 months ago
Posted in : JSP-Servlet


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


Advertisement
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
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 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
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 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
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
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...(); The given below code is responsible for hiding link after clicking
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 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... get(int index) The get() method reads int value at given index 
enable hyperlink
enable hyperlink  How to enable hyperlink
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 reads is short
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 at given
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
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
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
student details
student details  create an application for details of 1st to 5th standard students by using loops and scanner
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
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
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
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
Advertisements
 

 

 

DMCA.com