在jsp上显示特定类别的元素

时间:2017-05-03 10:51:26

标签: jsp

  

我创建此代码(categorie.jsp),显示具有ID,NAME和两个操作的类别的liste:update和delete..each categories包含产品

    <table border="1" width="25%" cellpadding="5">


                <tr style="color:white;">
                    <td ><center><b>Id</b></center></td>
                    <td><center><b>Title</b></center></td>
                    <td ><center><b>Actions</b></center></td>
                </tr>
                <%
                ClientDAO cd = new ClientDAO();
                PreparedStatement pr = (PreparedStatement)cd.method_Connection().prepareStatement("select * from categorie");
                ResultSet rs = pr.executeQuery();
               %>
               <%  while (rs.next()){ %>
            <tr>    
              <td ><center><b> <%=rs.getInt("id_cat") %></b></center></td>
              <td><center><b><%=rs.getString("name_cat") %></b></center></td>

              <td ><center><b>
                       <a href ="CategorieContent.jsp" >update</a> &nbsp &nbsp &nbsp &nbsp
                       <a href ="#">delete</a>
              </b></center></td>

           </tr>    
           <% } %> 

     </table>

当我在UPDATE时,它将转发到另一个jsp页面(products.jsp)。如何获取所选类别的ID并将其显示在页面products.jsp

1 个答案:

答案 0 :(得分:1)

单击更新时,将id作为查询字符串传递给jsp页面。在products.jsp页面

上获取此ID

<强> categorie.jsp

        <td>
            <center>
                <b> <a href="products.jsp?id=<%=rs.getInt("id_cat") %>">update</a> &nbsp &nbsp &nbsp
                    &nbsp <a href="#">delete</a>
                </b>
            </center>
        </td>

<强> products.jsp

<%
   String id=request.getParameter("id"); 
// Fetch products with this Category id
 %>