如何从一个jsp传递一个变量到另一个jsp页面

时间:2016-06-02 09:06:58

标签: javascript java mysql jsp

我需要将search.jsp表中已检查行的id传递给delete.jsp以便删除它,但是当我使用波纹管代码执行此操作时,没有任何反应,没有检查从数据库中删除的行

delete.jsp

        <%  


   Class.forName("com.mysql.jdbc.Driver"); 
   String myDatabase = "jdbc:mysql://localhost:3306/project_app?user=root&password=1234"; 
   Connection myConnection = DriverManager.getConnection(myDatabase);
   Statement myStatement = myConnection.createStatement();  



   myStatement.executeUpdate("DELETE * FROM Dest WHERE idDest ='"+request.getParameter("id1")+"'  ");
   myStatement.close();
   myConnection.close(); 
   %>

search.jsp的

    <%
   int id2;
   Class.forName("com.mysql.jdbc.Driver"); 
   String myDatabase = "jdbc:mysql://localhost:3306/project_app?user=root&password=1234"; 
   Connection myConnection = DriverManager.getConnection(myDatabase);
   Statement myStatement = myConnection.createStatement();  
   String search=request.getParameter("search");

  ResultSet rs = myStatement.executeQuery("SELECT * FROM dest WHERE Country='"+search+"' OR City='"+search+"'");    
  if (rs.next()) {



  %>
   <table style="width:100%">
 <table id="Dest_table">
       <tr>

    <th id="chke">Check </th>
    <th id="Country">Country</th>
    <th id="City">City</th> 
    <th id="URL">Url of Destination</th>
    <th id= "DestNO">Dest no </th>
    <th id="Act"> Action</th>

  </tr>
  <tr> <%while(rs.next()){ %>

    <td><input type="checkbox" name=chk onclick='window.location.assign('delete.jsp?id1='<%=rs.getString("idDest") %>")' /> </td>
    <td> <%=rs.getString("Country") %></td>
    <td> <%=rs.getString("City") %> </td> 
    <td> <a href=<%=rs.getString("Url") %> > <%=rs.getString("URL") %> </a>
    <td> <%=rs.getString("idDest") %>   </td>

    <TD><a href="delete.jsp"  class="button cross"  ></a>
    <TD><input <a href="edit.jsp"  type="submit" name="edit" value="Edit"  style="background-color: ff0000;font-weight:bold;color:#ffffff;"></TD> 
            </TR>


  </tr>
   <% }}
else { out.println("NOT FOUND <a href= \"choices.jsp\">Try Again</a>"); }%>
</table>




    <% 


   myStatement.close(); 
   myConnection.close(); %>

0 个答案:

没有答案