Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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?
- <td>
- <input type="text" id="new_name" name="na">
- </td>
- <td>
- <input type="text" id="new_qty" name="qu">
- </td>
- <td>
- <input type="text" id="new_pd" name="pu">
- </td>
- <td>
- <input type="text" id="new_dam" name="da">
- </td>
- <td>
- <select id="new_st" name="st">
- <option value="Active">Active</option>
- <option value="De-active">De-active</option>
- </select>
- </td>
- <td>
- <input type="text" id="new_des" name="de">
- </td>
- <td>
- <input type="button" name="myButton" class="add" onclick="add_row();" value="Add Row">
- </td>
- <script>
- function add_row() {
- var new_name = document.getElementById("new_name").value;
- var new_qty = document.getElementById("new_qty").value;
- var new_pd = document.getElementById("new_pd").value;
- var new_dam = document.getElementById("new_dam").value;
- var new_st = document.getElementById("new_st").value;
- var new_des = document.getElementById("new_des").value;
- var table = document.getElementById("data_table");
- var table_len = (table.rows.length) - 1;
- 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>";
- document.getElementById("new_name").value = "";
- document.getElementById("new_qty").value = "";
- document.getElementById("new_pd").value = "";
- document.getElementById("new_dam").value = "";
- document.getElementById("new_st").value = "";
- document.getElementById("new_des").value = "";
- </script>
- <jsp:useBean id="k" class="iot.bean"/>
- <jsp:setProperty name="k" property="ne" param="na"/>
- <jsp:setProperty name="k" property="qy" param="qu"/>
- <jsp:setProperty name="k" property="pe" param="pu"/>
- <jsp:setProperty name="k" property="ds" param="da"/>
- <jsp:setProperty name="k" property="ss" param="st"/>
- <jsp:setProperty name="k" property="dn" param="de"/>
- public void result() throws Exception {
- System.out.println("helloEEEEEEEEE");
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("hello!");
- Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/fun","root","root");
- //Statement st=c.createStatement();
- System.out.println("hello");
- PreparedStatement ps= c.prepareStatement("insert into asset values(?,?,?,?,?,?)");
- ps.setString(1, ne);
- ps.setInt(2, qy);
- ps.setString(3, pe);
- ps.setInt(4, ds);
- ps.setString(5, ss);
- ps.setString(6, dn);
- ps.executeUpdate();
- System.out.println("registered succesfully");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement