javascript - My response.jsp won't populate fields properly -


i been working on web app connects database populates designated fields. edit of netbeans tutorial. well, setup database , tested populating table on response page information. problem arises on index.jsp, when pick 1 of titles view list. used titles instead of id numbers select books:

select titlefk booklist 

instead of:

select id, titlefk booklist 

because drop down box show both id , title choices. after selecting book title , clicking submit key, should populate next page corresponding info database.

pictures of sites: http://imgur.com/a/kvemn

the table above temporary measure check database connected. selected third option on database yet response.jsp keeps populating information of first book. not sure missing on code, hope point me on right direction.

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>  <sql:query var="books" datasource="jdbc/ifpbooklistrt"> select titlefk booklist </sql:query>  <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />         <title>ifpbooklist homepage</title>     <link rel="stylesheet" type="text/css" href="style.css"> </head> <body>         <h1>welcome ifpbooklist, personal book selection</h1>      <table border="0">         <thead>             <tr>                 <th>here find personal books to-do list</th>             </tr>         </thead>         <tbody>             <tr>                 <td>to view details, select book below</td>             </tr>             <tr>                 <td><form action="response.jsp">                         <strong>select book:</strong>                         <select name="subject_id">                             <c:foreach var="row" items="${books.rowsbyindex}">                                 <c:foreach var="column" items="${row}">                                 <option value="<c:out value="${column}"/>"><c:out value="${column}"/></option>                                 </c:foreach>                             </c:foreach>                         </select>                         <input type="submit" value="submit" name="submit" />                     </form>                 </td>             </tr>         </tbody>     </table>   </body> 

and here response.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>  <sql:query var="bookquery" datasource="jdbc/ifpbooklistrt">     select * booklist,book     book.id=booklist.id  </sql:query>  <c:set var="bookdetails" value="${bookquery.rows[0]}"/>  <table border="1">     <!-- column headers -->     <tr>         <c:foreach var="columnname" items="${bookquery.columnnames}">         <th><c:out value="${columnname}"/></th>     </c:foreach> </tr> <!-- column data --> <c:foreach var="row" items="${bookquery.rowsbyindex}">     <tr>     <c:foreach var="column" items="${row}">         <td><c:out value="${column}"/></td>     </c:foreach>     </tr> </c:foreach> </table> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />         <title>${bookdetails.title}</title>     </head>     <body>        <table border="0">     <thead>         <tr>         <th colspan="2">${bookdetails.title}</th>         </tr>         <tr>             <td>edition: <a href="placeholder">${bookdetails.edition}</a></td>         </tr>     </thead>     <tbody>         <tr>             <td>                 <strong>description: </strong>             </td>             <td>                 {placeholder}             </td>             <link rel="stylesheet" type="text/css" href="style.css">         </tr>         <tr>             <td>                 <strong>publisher </strong>             </td>             <td>                 ${bookdetails.publisher}             </td>         </tr>         <tr>             <td>                 <strong>                     published date                 </strong>             </td>             <td>                 ${bookdetails.datepublished}             </td>         </tr>         <tr>             <td>                 <strong>author </strong>             </td>             <td>                 ${bookdetails.author}             </td>         </tr>          <tr>             <td>                 <strong>isbnnumber </strong>             </td>             <td>                 <a href="placeholder">${bookdetails.isbnnumber}</a>                 <br>             </td>          </tr>          <tr>              <td>                  <strong>amazon link: </strong></td>              <td>                  <a href="placeholder">${bookdetails.amazonlink}</a>                 <br>              </td>          </tr>     </tbody>    </table> </body> 

what you're missing quite simple. should able whip shape quite easily.

  • the job of index.jsp file present user list of options, allow them select one, , pass selected option on response.jsp.
  • the job of response.jsp take selected option, , display more details it.

you're never reading selected option, see query in response.jsp pulling of books , selecting first 1 returned database (e.g. rows[0] ):

<sql:query var="bookquery" datasource="jdbc/ifpbooklistrt">     select * booklist,book     book.id=booklist.id </sql:query>  <c:set var="bookdetails" value="${bookquery.rows[0]}"/> 

what need in response.jsp is:

1) read subject_id parameter passed in index.jsp.

2) use subject_id filter (via sql clause) bookquery book selected returned.

returning tutorial, if take close near end, @ item 3 below response.jsp, you'll see how it:

<sql:query var="counselorquery" datasource="jdbc/ifpwafcad">     select * subject, counselor     counselor.counselor_id = subject.counselor_idfk     , subject.subject_id = ? <sql:param value="${param.subject_id}"/> </sql:query> 

hope helps!


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -