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



Home Answers Viewqa JSP-Interview-Questions how to get multiple hyperlink values from a table column to another jsp file?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


hamam
how to get multiple hyperlink values from a table column to another jsp file?
1 Answer(s)      3 years and 7 months ago
Posted in : JSP-Interview Questions


dear sir:

this is what i'm trying to do, i have 3 JSP files. first file named "index" asks the user to enter the itemid and and search for it. second file named "dbtable" will get the parameter from "index" and search for the user string in the database, as a result a table will come up with 3 columns itemid, itemname, and description. now my itemid column is all in hyperlinks, so if the user click on one of these hyperlinks the third file named "table2" should show the specific details from that hyperlink which was clicked. there are 3 columns in "table2" which are itemid, subinventoryid, and transactionquantity, please note that "dbtable" and "table2" have relation in itemid. please show me how can i copy the hyperlink value to that third jsp file "table2", or if you have another way in JSP please share. these are my codes:

***index.jsp***

<html>

<head>  

<title>searching DB</title>

</head>

<body>

<ht>TST1 DB</h1>

<form action="dbtable.jsp" method="post" >

<p> Please Enter Item ID LIKE(%)</p>

<input type="text" name="id"/>

<input type="submit" name="submit" value="Search"/>

</form>

</body>

</html>


***dbtable.jsp***

<html>

<head>

<title>DataBase</title>

</head>

<body>

<%
String URL = "";

Class.forName("oracle.jdbc.OracleDriver").newInstance();

conn = DriverManager.getConnection(URL, "root", "root");

stmt = conn.createStatement();

String id = request.getParameter("id");

String QueryString = "select * from items where organization_id = 84 and
"+"item_id LIKE '"+id+"'";

rs = stmt.executeQuery(QueryString);

%>

<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"/>

<table  border="1" style="table-layout: fixed" >

<th>Item ID</th>    
<th>Item Name</th>
<th>Description</th>

<%
while (rs.next()) {
%>

<tr>

<td><%=rs.getInt("item_id")%></a> </td>

<TD><%=rs.getString("item_name")%></TD>

<TD><%=rs.getString("description")%></TD>

</tr>

<%   }    %>
<%


rs.close();
stmt.close();
conn.close();
%>

</table>    

</center>
</body>
</html>



***table2.jsp***

<html>
    <head>
    <title>DataBase2</title>

    </head>

<body>

<%              
        String URL = "";

        Class.forName("oracle.jdbc.OracleDriver").newInstance();

        conn = DriverManager.getConnection(URL, "root", "root");

        stmt = conn.createStatement();



        String QueryString = "select * from mtl_onhand_quantities"
        + " where item_id = ''"

    rs = stmt.executeQuery(QueryString);

%>

<center>

<table  border="1" style="table-layout: fixed" >

    <th>item code</th>
    <th>subinventory code</th>
    <th>onhand</th>       

    <%
    if  (rs.next()) {
    %>

    <tr>

       <TD><%=rs.getInt("item_id")%>"/> </TD>
       <TD><%=rs.getString("subinventory_code")%> </TD>
       <TD><%=rs.getInt("transaction_quantity")%> </TD>


    </tr>          

    <%   }    %>
    <%
    // close all the connections.
    rs.close();
    stmt.close();
    conn.close();
  %>

  </table>    

</center>
</body>
</html>

thank you


Advertisement
View Answers

June 2, 2011 at 3:43 PM


1)search.jsp:

<html>
<form method="post" action="dbtable.jsp">
Enter id: <input type="text" name="id">
<input type="submit" value="Search">
</form>
</html>

2)dbtable.jsp:

<%@page import="java.sql.*"%>
<html>
<table border="1">
<%
try{
String v=request.getParameter("id");
int id=Integer.parseInt(v);
Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from items where itemid="+id+"");
while(rs.next()){
    %>
<tr><td><a href="table2.jsp?id=<%=rs.getString("itemid")%>"><%=rs.getString("itemid")%></a></td><td><%=rs.getString("item")%></td><td><%=rs.getString("description")%></td></tr>
<%
}
}
catch(Exception e){
    System.out.println(e);
}
%>
</table>
</html>

3)table2.jsp:

<%@page import="java.sql.*"%>
<html>
<table border="1">
<%
String v=request.getParameter("id");
int id=Integer.parseInt(v);
Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from subinventory where itemid="+id+"");
while(rs.next()){
    %>
<tr><td><%=rs.getInt("itemid")%></td><td><%=rs.getInt("subinventoryid")%></td><td><%=rs.getInt("quantity")%></td></tr>
<%
}
%>
</table>
</html>


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com