In this tutorial , the text is inserted into database table using JSP & jQuery.
In this tutorial , the text is inserted into database table using JSP & jQuery.In this tutorial , the text is inserted into database table using JSP & jQuery. In the below example, the first JSP page is use to display text box in which we type data. It also contain jQuery script ,to connect to another JSP page and show result using "fadeIn" effect. The second JSP page contains code for connectivity and fetching data from database table.
insert.jsp
<%@ page language="java" import="java.sql.*" errorPage="" %> <html> <head> <title>GET VALUE FROM TABLE</title> <script src="jquery-1.4.2.js" type="text/javascript"></script> <script src="insert.js" type="text/javascript"></script> </head> <body> <form id="form" method="post"> <h3>Send message to Administrator(Plz Type below)</h3> <textarea cols="30" rows="2" type="text" id="content" maxlength= "145" > </textarea><br /> <input id="submit" type="submit" value="Send Message"/> <input id="reset" type="reset" value="Reset"/> </form> <p id="result"></p> <body> </html> |
insert.js
$(document).ready(function() { $('#form').submit(function(){ var content= $('#content').val(); $.ajax({type:"post",url:"demo.jsp",data:"content=" +content,success:function(msg){$('#result').hide(); $("#result").html("<h3>" + msg + "</h3>").fadeIn("slow"); } }); return false; }); }); |
demo.jsp
<%@ page language="java" import="java.sql.*" errorPage="" %> ("jdbc:mysql://192.168.10.13:3306/ankdb", "root", "root"); ('"+request.getParameter("content")+"')"); |
OUTPUT
After typing message and pressing button "Send Message" :