
i am using JSP.i want to insert data into database and also want to display the things i have entered in the same page inside the corresponding fields in which i have entered these data.plz some one help me..i m going to submit my project next week..

1)employee.jsp:
<html>
<head>
<script>
var xmlHttp;
function showState(){
var str1=document.getElemenetByID("txt1").value;
var str2=document.getElemenetByID("txt2").value;
var str3=document.getElemenetByID("txt3").value;
if(typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert ("Browser does not support XMLHTTP Request")
return
}
var url= "emp.jsp";
url += "?val1=" +str1+"&&val2="+str2+"&&val3="+str3;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var v=xmlHttp.responseText;
var strar = v.split(":");
document.getElementById("txt1").value= strar[1];
document.getElementById("txt2").value= strar[2];
document.getElementById("txt3").value= strar[3];
}
}
</script>
</head>
<body>
<table>
<tr><td>Enter Name:</td><td><input type="text" id="txt1"></td></tr>
<tr><td>Enter Address:</td><td><input type="text" id="txt2"></td></tr>
<tr><td>Enter Email:</td><td><input type="text" id="txt3"> </td></tr>
<tr><td><input type="button" value="Submit" onclick="showState();"></td><td>
</table>
</body>
</html>
2)emp.jsp:
<%@page language="java" import ="java.sql.*" %>
<%
String val1 = request.getParameter("val1").toString();
String val2 = request.getParameter("val2").toString();
String val3 = request.getParameter("val3").toString();
String data="";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into data(name,address,email) values('"+val1+"','"+val2+"','"+val3"')");
ResultSet rs = stmt.executeQuery( "SELECT * FROM data");
String id="";
while(rs.next())
{
data = ":" + rs.getString("name") + ":" + rs.getString("address") +":"+ rs.getString("email");
}
out.println(data);
%>
For more information, visit the folowing links:
http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.