how to get multiple hyperlink values from a table column to another jsp file?

Ads

 
 
 

Share on Google+Share on Google+

hamam
how to get multiple hyperlink values from a table column to another jsp file?
1 Answer(s)      5 years and 11 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

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

<[email protected] 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:

<[email protected] 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>

Ads









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training How to retrieve and display image from database in Java? How to retrieve image from mysql database in JSP? How to store and retrieve image from database in JSP? How to retrieve blob image from database in JSP? How to retrieve image from database using jsp and servlet? Retrieve image from database using servlet and display in JSP why do not required application restart after jsp changes? How to use contentType Attribute in JSP? How to connect to MySQL in JSP? JSP Comment Types with example How to use ajax in jsp? How to access the database from JSP? how to show image as a link which path coming from database jsp netbeans javascript Logos on mail inbox. I want to update the multiple values of database depending on checkbox..? Please help me out.. jsp 18/04/2013 JSTL how to access element added via javascript dynamically using jsp code Electronic spreadsheets are useful in situation An E-mail protocol for storage JSP JSP JSP jsp servlets Exception: com.mysql.jdbc.Driver display data from database on selecting option of dropdownlist display data from database on selecting option of dropdownlist display data from database on selecting option of dropdownlist display data from database on selecting option of dropdownlist Jsp Query run command prompt from jsp program question for c++ please help me how to set up Netbeans for JSP 3 dropdown list from the database using JSP autocompletion in textfield fetching from database in jsp openning the pdf or doc file in same jsp EXT JS tt need coding JSp session time out how to display values from database into table using jsp how to set the class path variable in tomcat ? need help please online examination system mini project problem in writing coding. Please help me. How to read the body content of custom tag? need help...................please please help me

Ads

 
Advertisement null

Ads