Please help me, My Question is -
How to store user registration details into database(MS Access database), and how to validate the username and password, If again the same person logins. Please write the programs in Servlets,JavaBeans and jsp.
First of all, connect jsp to MS access database. So follow these steps:
1)Go to the start->Control Panel->Administrative Tools-> data sources.
2)Click Add button and select the driver Microsoft Access Driver(*.mdb).
3)After selecting the driver, click finish button.
4)Then give Data Source Name and click ok button.
5)Your DSN will get created.
6) Restart your tomcat server and run your jsp code.
1)form.jsp:
<html> <head> <script type="text/javascript"> function check(value){ xmlHttp=GetXmlHttpObject() var url="check.jsp"; url=url+"?name="+value; xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged(){ if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ var showdata = xmlHttp.responseText; alert(showdata); document.getElementById("name").value=" "; } } function GetXmlHttpObject(){ var xmlHttp=null; try{ xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> </head> <body> <form name="form" action="insert.jsp"> <pre> UserName: <input type="text" name="name" id="name" onkeyup="check(this.value);"> Password: <input type="password" name="pass" id="pass"> Address : <input type="text" name="address" id="address"> Contact : <input type="text" name="contact" id="contact"> Email : <input type="text" name="email" id="email"> <input type="submit" value="Submit"> </pre> </form> </body> </html>
2)check.jsp:
<%@ page import="java.sql.*" %> <% String name = request.getParameter("name").toString(); System.out.println(name); String data =""; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where username='"+name+"'"); int count=0; while(rs.next()) { count++; } if(count>0) { data="Not Available"; } else { } out.println(data); System.out.println(data); } catch (Exception e) { System.out.println(e); } %>
3)insert.jsp:
<%@page import="java.sql.*"%> <% String user=request.getParameter("name"); String pass=request.getParameter("pass"); String address=request.getParameter("address"); String contact=request.getParameter("contact"); String email=request.getParameter("email"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:student","",""); Statement st=con.createStatement(); int i=st.executeUpdate("insert into data(username,password,address,contact,email) values('"+user+"','"+pass+"','"+address+"','"+contact+"','"+email+"')"); out.println("Data is inserted successfully"); %>
Hi, Please use servlets, where the Servlet program will store or retrieve the user details. And also use PreparedStament(JDBC) for storing information into database.
By the way.. Thanks for the program and Please do the needful.
Ads