Newbie: JSTL question, delete record link

Discussion in 'Java' started by Cardinal, Jan 12, 2006.

  1. Cardinal

    Cardinal Guest

    I have a small application that reads and displays book information
    from a database. It also allows the user to add books and their prices.
    It's code is below. I want to add a delete link along side of each book
    that allows the user to delete a book. No confirm message or anything
    like that - I'm just interested in getting it to work. Can anyone give
    me a hint on what JSTL code might accomplish this. If that works then
    I'm sure I can use it to develop an edit link as well. Thanks very
    much.

    P.S. This is a modified example from the Beginning JSP 2.0 book by wrox
    but I'm trying to get it to do more to increase my understanding.
    Thanks again.

    ******************************************************************
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

    <sql:setDataSource var="datasource" driver="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost/publish" user="publish" password="wrox" />

    <c:if test="${param.title != null}">
    <sql:update dataSource="${datasource}">
    INSERT INTO book (title, price)
    VALUES (?, ?)
    <sql:param value="${param.title}" />
    <sql:param value="${param.price}" />
    </sql:update>
    </c:if>


    <sql:query var="books" dataSource="${datasource}">
    select id, title, price FROM book
    </sql:query>

    <html>
    <head>
    <title>First JSP Database</title>
    <style>
    #reg{
    font-family:"arial", "verdana";
    font-size:12px;
    }
    </style>



    </head>
    <body>
    <form method="post">
    <table id="reg">
    <tr>
    <td>ID</td>
    <td>Title</td>
    <td>Price</td>
    <td></td>
    <td></td>
    </tr>
    <c:forEach var="row" items="${books.rows}">
    <tr>
    <td width="10%"><c:eek:ut value="${row.id}" /></td>
    <td><c:eek:ut value="${row.title}" /></td>
    <td width="10%"><c:eek:ut value="${row.price}" /></td>
    <td width="10%">Edit</td>
    <td width="10%">Delete</td>
    </tr>
    </c:forEach>
    <tr>
    <td>&nbsp;</td>
    <td><input type="Text" name="title" size="30" /></td>
    <td><input type="Text" name="price" size="5" /></td>
    </tr>
    <tr>
    <td colspan="3" align="center">
    <input type="submit" value="Save New Book" />
    </td>
    </tr>
    </table>
    </form>


    </body>
    </html>
    ******************************************************************
     
    Cardinal, Jan 12, 2006
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.