Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. I have written client side code using html and javascript, and server side code using jsp and java bean to connect to the database. How to communicate between javascript and jsp?
  2.  
  3. <td>
  4. <input type="text" id="new_name" name="na">
  5. </td>
  6. <td>
  7. <input type="text" id="new_qty" name="qu">
  8. </td>
  9. <td>
  10. <input type="text" id="new_pd" name="pu">
  11. </td>
  12. <td>
  13. <input type="text" id="new_dam" name="da">
  14. </td>
  15. <td>
  16. <select id="new_st" name="st">
  17. <option value="Active">Active</option>
  18. <option value="De-active">De-active</option>
  19. </select>
  20. </td>
  21. <td>
  22. <input type="text" id="new_des" name="de">
  23. </td>
  24. <td>
  25. <input type="button" name="myButton" class="add" onclick="add_row();" value="Add Row">
  26. </td>
  27.  
  28. <script>
  29. function add_row() {
  30.  
  31. var new_name = document.getElementById("new_name").value;
  32. var new_qty = document.getElementById("new_qty").value;
  33. var new_pd = document.getElementById("new_pd").value;
  34. var new_dam = document.getElementById("new_dam").value;
  35. var new_st = document.getElementById("new_st").value;
  36. var new_des = document.getElementById("new_des").value;
  37.  
  38. var table = document.getElementById("data_table");
  39. var table_len = (table.rows.length) - 1;
  40. var row = table.insertRow(table_len).outerHTML = "<tr id='row" + table_len + "'><td id='name_row" + table_len + "'>" + new_name + "</td><td id='qty_row" + table_len + "'>" + new_qty + "</td><td id='pd_row" + table_len + "'>" + new_pd + "</td><td id='dam_row" + table_len + "'>" + new_dam + "</td><td id='st_row" + table_len + "'>" + new_st + "</td><td id='des_row" + table_len + "'>" + new_des + "</td><td><input type='button' id='edit_button" + table_len + "' value='Edit' class='edit' onclick='edit_row(" + table_len + ")'> <input type='button' id='save_button" + table_len + "' value='Save' class='save' onclick='save_row(" + table_len + ")'> <input type='button' value='Delete' class='delete' onclick='delete_row(" + table_len + ")'></td></tr>";
  41.  
  42.  
  43. document.getElementById("new_name").value = "";
  44. document.getElementById("new_qty").value = "";
  45. document.getElementById("new_pd").value = "";
  46. document.getElementById("new_dam").value = "";
  47. document.getElementById("new_st").value = "";
  48. document.getElementById("new_des").value = "";
  49.  
  50. </script>
  51.  
  52. <jsp:useBean id="k" class="iot.bean"/>
  53.  
  54. <jsp:setProperty name="k" property="ne" param="na"/>
  55. <jsp:setProperty name="k" property="qy" param="qu"/>
  56. <jsp:setProperty name="k" property="pe" param="pu"/>
  57. <jsp:setProperty name="k" property="ds" param="da"/>
  58. <jsp:setProperty name="k" property="ss" param="st"/>
  59. <jsp:setProperty name="k" property="dn" param="de"/>
  60.  
  61. public void result() throws Exception {
  62. System.out.println("helloEEEEEEEEE");
  63.  
  64.  
  65. Class.forName("com.mysql.jdbc.Driver");
  66. System.out.println("hello!");
  67. Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/fun","root","root");
  68. //Statement st=c.createStatement();
  69. System.out.println("hello");
  70.  
  71. PreparedStatement ps= c.prepareStatement("insert into asset values(?,?,?,?,?,?)");
  72.  
  73. ps.setString(1, ne);
  74. ps.setInt(2, qy);
  75. ps.setString(3, pe);
  76. ps.setInt(4, ds);
  77. ps.setString(5, ss);
  78. ps.setString(6, dn);
  79.  
  80. ps.executeUpdate();
  81. System.out.println("registered succesfully");
  82.  
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement