Вы находитесь на странице: 1из 3

<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.user_name.value==""){ //Please enter username alert("Please enter User Name."); theForm.user_name.focus(); return false; }

if(theForm.lastname.value==""){ //Please enter lastname alert("Please enter Last Name."); theForm.lastname.focus(); return false; } if(theForm.email.value==""){ alert("Please enter email!"); theForm.email.focus(); return false; } if(!checkEmail(theForm.email.value)){ theForm.email.focus(); return false; } if(theForm.position.value==""){ //Please enter position alert("Please enter Position.");

theForm.position.focus(); return false; } if(theForm.salary.value==""){ //Please enter salary alert("Please enter salary."); theForm.salary.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 validateFor m(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> May 14, 2008 at 6:04 PM <%@ 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+"','"+las tname+"','"+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(); } %>

Вам также может понравиться