| | |
how to select the isbn number in table and get all books of isbn selected
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Solved Threads: 0
i have a table displayed with bookisbn , booktitle and bookauthor etc..in which i have to make the bookisbn column values as hyperlink to a page name bookinfo.jsp which will diplay all copies of the book under the clicked isbn number .
i am attaching the code below:
{code viewbooksforsale.info which displays all books in database and has values of isbn column as hyperlinks}
*
*{code viewbookinfo.jsp generated view once a user selects an isbn number in viewbookforsales.jsp } *
*
{code probookinfo.jsp -- process jsp file for viewbookinfo.jsp}
i am attaching the code below:
{code viewbooksforsale.info which displays all books in database and has values of isbn column as hyperlinks}
jsp Syntax (Toggle Plain Text)
<?xml version="1.0" encoding ="UTF-8"?> <%-- file location of the jsp --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Books For Sale</title> </head> <body> <%--debugging code--%> <%@ include file="debug.jsp" %> ONLINE BOOK TRADING SYSTEM <c:url var="HmePgeURL" value="/cw/router/home" scope="page"/> <a href="${HmePgeURL}">Home</a> <c:url var="BSPgeURL" value="/cw/router/login" scope="page"/> <a href="${BSPgeURL}">Buy or Sell</a> <c:url var="UregPgeURL" value="/cw/router/userregistration" scope="page"/> <a href="${UregPgeURL}">User Registration</a> <%-- check for database Error --%> <c:if test="${!empty requestScope.reqQueryErrorMessage}" var="pgeDatabaseError" scope="page"> Database Error </c:if> <%-- check for empty item table --%> <c:if test="${not pgeDatabaseError}"> <c:if test="${booksFromQuery.rowCount == 0}" var= "pgeEmptyTable" scope="page" > There Are No Items In The Table </c:if> </c:if> Books For Sale ! <%-- Display Books --%> <c:if test="${not pgeDatabaseError and not pgeEmptyTable}"> <table border="1" align="center" cellpadding="2" cellspacing="0" width ="984"> <tr bgcolor="#66CCFF"> <td width="15"> ISBN </td> <td width="268"> Title </td> <td width="198"> Author </td> <td width="10"> Price </td> <td width="15"> Condition </td> <td width="15"> Status </td> </tr> <c:forEach items="${booksFromQuery.rows}" var="myRow"> <tr><c:url var="BookInfoPgeURL" value="/cw/router/viewbookinfo" scope="page"/> <td width="15"> <a href= "$BookInfoPgeURL" onclick="afadf">${myRow.dbItemISBN}</a> </td> <c:set var="ISBNselected" value="${myRow.dbItemISBN}" scope="request" /> <td width="268"> ${myRow.dbItemTitle} </td> <td width="198"> ${myRow.dbItemAuthor} </td> <td width="10"> ${myRow.dbItemPrice} </td> <td width="15"> ${myRow.dbItemCondition} </td> <td width="15"> ${myRow.dbItemStatus} </td> </tr> </c:forEach> </table> </c:if> <%-- debugging code --%> <%-- for local page-scoped objects --%> <c:if test="${sessDebug == 'true'}"> <table border="1"> <c:forEach var="item" items="${pageScope}"> <tr> <td>pageScope object</td> <td>${item.key}</td> <td>${item.value}</td> </tr> </c:forEach> </table> </c:if> </body> </html>
*
*{code viewbookinfo.jsp generated view once a user selects an isbn number in viewbookforsales.jsp } *
jsp Syntax (Toggle Plain Text)
<?xml version="1.0" encoding ="UTF-8"?> <%-- file location of the jsp --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>BOOK INFO</title> </head> <body> <div align="center"><c:url var="HmePgeURL" value="/cw/router/home" scope="page"/><a href="${HmePgeURL}">Home</a> <c:url var="BSPgeURL" value="/cw/router/login" scope="page"/> <a href="${BSPgeURL}">Buy or Sell</a> <c:url var="UregPgeURL" value="/cw/router/userregistration" scope="page"/> <c:url var='pgeviewbooksURL' value='/cw/router/viewbooksforsale' scope='page'/><a href="${pgeviewbooksURL}">Online Book Sale</a> </div> <%-- check for database Error --%> <c:if test="${!empty requestScope.reqQueryErrorMessage}" var="pgeDatabaseError" scope="page"> Database Error </c:if> <%-- check for empty item table --%> <c:if test="${not pgeDatabaseError}"> <c:if test="${booksinfoFromQuery.rowCount == 0}" var= "pgeEmptyTable" scope="page" > There Are No Items In The Table </c:if> </c:if> <%-- display book info --%> <c:if test= "${not pgeDatabaseError and not pgeEmptyTable}"> <p align="center"> </p> <div align="center"> <table width="359" cellpadding="5"> <tr> <td width="187"><label>COPIES AVAILABLE</label> </td> <td width="144"><input name="textfield" type="text" value="${fn:length(items}" /></td> </tr> </table> </div> <c:forEach items="${booksinfoFromQuery.rows}" var="myRow"> <p align="center"> </p> <div align="center"> <table width="671" cellpadding="5"> <tr> <td>ITEM ID </td> <td><input type="text" name="textfield" value="${myRow.dbItemId}"/></td> </tr> <tr> <td width="209"><label>ISBN</label> </td> <td width="434"><input type="text" name="textfield" value="${myRow.dbItemISBN} "/></td> </tr> <tr> <td><label>TITLE</label> </td> <td><input name="text" type="text" value="${myRow.dbItemTitle}" /></td> </tr> <tr> <td><label>AUTHOR</label> </td> <td><input name="textarea" type="text" value="${myRow.dbItemAuthor}" /></td> </tr> <tr> <td><label>BOOK INFO </label> </td> <td><input name="textarea" type="text" value="${myRow.dbItemInfo}" /></td> </tr> <tr> <td><label>CONDITION</label> </td> <td><input type="text" name="textfield" value="${myRow.dbItemCondition} " /></td> </tr> <tr> <td><label>STATUS</label> </td> <td><input type="text" name="textfield" value="${myRow.dbItemStatus}"/></td> </tr> <tr> <td><label>PRICE</label> </td> <td><input type="text" name="textfield" value="${myRow.dbItemPrice}"/></td> </tr> <hr /> </table> </div> </c:forEach> </c:if>
{code probookinfo.jsp -- process jsp file for viewbookinfo.jsp}
jsp Syntax (Toggle Plain Text)
<?xml version="1.0" encoding ="UTF-8"?> <%-- \WEB-INF\jsp\cwjsps\probookinfo.jsp --%> <%-- Probookinfo --%> <%-- file location of the jsp --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%-- execute the query --%> <c:catch var="pgeQueryError"> <sql:query var="booksinfoFromQuery" scope="request"> SELECT dbItemId,dbItemInfo,dbItemISBN,dbItemTitle,dbItemAuthor,dbItemPrice,dbItemCondition,dbItemStatus FROM item WHERE dbItemISBN ="${ISBNselected}" </sql:query> </c:catch> <%-- check query error --%> <c:choose> <c:when test="${not empty pgeQueryError}"> <%-- Database Error --%> <c:set var="reqOutcome" scope="session" value="failure" /> <c:set var="reqQueryErrorMessage" scope="request" value="${pgeQueryError.message}" /> <jsp:forward page="/WEB-INF/jsp/cwjsps/test.jsp"/> </c:when> <c:otherwise> <c:set var="reqOutcome" scope="session" value="success" /> </c:otherwise> </c:choose> <jsp:forward page="/WEB-INF/jsp/cwjsps/viewbookinfo.jsp"/> <%-- display book info --%> <%-- display trader own page after login --%>
Last edited by peter_budo; Apr 3rd, 2008 at 12:19 pm. Reason: Changed {code} to [code]
![]() |
Other Threads in the JSP Forum
- Previous Thread: Jsp exporting to word
- Next Thread: why do we need filter in a servlet
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






