Hi
<html>
<title>registration form in jsp</title>
<head>
<script type="text/javascript">
function checkEmail(email) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}
alert("Invalid email address.Please Enter again.")
return (false);
}
function validateForm(theForm){
if(theForm.email.value==""){
alert("Please enter email!");
objForm.email.focus();
return false;
}
if(!checkEmail(theForm.email.value)){
theForm.email.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<table border="1" width="50%" bgcolor="pink">
<tr>
<td width="100%">
<form method="POST" action="RegistrationAction.jsp" onsubmit="return validateForm(this);">
<h2 align="center">User registration form</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="user_name" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Last Name:</b></td>
<td width="50%"><input type="text" name="lastname" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Email:</b></td>
<td width="50%"><input type="text" name="email" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Position:</b></td>
<td width="50%"><input type="text" name="position" size="20"></td>
</tr>
<tr>
<td width="50%"><b>Salary:</b></td>
<td width="50%"><input type="text" name="salary" size="20"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>
</td>
</tr>
</table>
</body>
</html>
----------------------------
<%@ page language="java" import="java.sql.*" %>
<%
Connection con = null;
String url = "jdbc:
mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
try{
Statement st = con.createStatement();
String username=request.getParameter("user_name");
String lastname=request.getParameter("lastname");
String email=request.getParameter("email");
String position=request.getParameter("position");
String salary=request.getParameter("salary");
int val = st.executeUpdate("insert user_Register values(id,'"+username+"','"+lastname+"','"+email+"','"+position+"','"+salary+"')");
con.close();
out.println("successfully insert data into database!");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
---------------------
read for more information,
http://www.roseindia.net/jsp/