2011-12-08 54 views
0

原諒我,我從來沒有使用過jsp,並且對html也有一定的瞭解。製作表單按鈕改變當前頁面的顯示

我想要的是一個窗體按鈕,它將從窗體中獲取輸入並在SQL查詢中使用它,並且在按下按鈕時顯示一個包含查詢結果的表。

我有一些我已經使用過的示例代碼,但我無法弄清楚如何使按鈕的動作在當前頁面上創建一個表格。

我的體內,我有:

<form action="demo.jsp" method="post"> 
    <table> 
     <tr> 
      <td> Which country?</td> 
      <td><input type='text' name='country' value="${country}"></td> 
     </tr> 
     <tr> 
      <td></td> 
      <td><input type='submit' name='action2' value='Search'> 
     </tr> 
    </table> 
</form> 

,然後外面我有:

<c:if test="${param.action == 'Search'}"> 
    <table border='1'> 
     <tr> 
      <th>Year</th> 
      <th>Country</th> 
      <th>Position</th> 
     </tr> 

     <sql:query var="QryCountry"> 
      Select * 
      from db.TEAM 
      where country = ? 
       <sql:param value="${country}" /> 
     </sql:query> 
     <c:forEach var="row" items="${QryCountry.rows}"> 
       <tr> 
        <td><c:out value="${row.team_year}" /></td> 
        <td><c:out value="${row.country}" /></td> 
        <td><c:out value="${row.position}" /></td> 
       </tr> 
     </c:forEach> 
     <c:set var="country" value="" /> 
    </table> 
</c:if> 

但按下按鈕不會出現被做任何事情。有什麼建議麼?如有必要,我很樂意澄清任何事情。

回答

1

糾正我如果我錯了。在你的代碼片段中查看<c:if/>表達式,它應該是,

<c:if test="${param.action2 == 'Search'}"> 
+0

謝謝,就是這樣。接得好! – Rowhawn

相關問題