hi I m developing a project on hospital management and I m not able to retrieve the user information..
now their is a login and registration page for newuser. after the user has filled the form he should go to the welcome page where he could see the information he has filled in the form and various other links..
now my question is how to retrieve this information of user after registration or after he has logged in...
1)login.jsp:
<html> <script> function validate(){ var username=document.form.user.value; var password=document.form.pass.value; if(username==""){ alert("Enter Username!"); return false; } if(password==""){ alert("Enter Password!"); return false; } return true; } </script> <form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();"> <table> <tr><td>Username:</td><td><input type="text" name="user"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass"></td></tr> <tr><td></td><td><input type="submit" value="Login"></td></tr> <tr><td></td><td><a href="register.jsp">Register Here</a></td></tr> </table> </form> </html>
2)check.jsp:
<%@page import="java.sql.*"%> <% try{ String user=request.getParameter("user"); String pass=request.getParameter("pass"); Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'"); int count=0; while(rs.next()) { count++; } if(count>0){ out.println("welcome "+user); Statement s=con.createStatement(); ResultSet rst=s.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'"); while(rst.next()){ System.out.println(rst.getString("firstname")); %> <h3>Your Account Information</h3> <table> <tr><td>FirstName:</td><td><input type="text" name="name" value="<%=rst.getString("firstname")%>"></td></tr> <tr><td>LastName:</td><td><input type="text" name="name" value="<%=rst.getString("lastname")%>"></td></tr> <tr><td>Address:</td><td><input type="text" name="name" value="<%=rst.getString("address")%>"></td></tr> <tr><td>Contact No:</td><td><input type="text" name="name" value="<%=rst.getString("contactNo")%>"></td></tr> <tr><td>Email:</td><td><input type="text" name="name" value="<%=rst.getString("email")%>"></td></tr> </table> <% } } else { response.sendRedirect("login.jsp"); } } catch(Exception e){ System.out.println(e); } %>
3)register.jsp:
<html> <script> function validate(){ if(document.form.uname.value == ""){ alert("Please enter user name." ); document.form.uname.focus(); return false; } if(document.form.fname.value == ""){ alert("Please enter first name." ); document.form.fname.focus(); return false; } if(document.form.lname.value == ""){ alert("Please enter last name." ); document.form.lname.focus(); return false; } if(document.form.address.value == ""){ alert("Please enter address." ); document.form.address.focus(); return false; } if(document.form.contact.value == ""){ alert("Please enter contact no." ); document.form.contact.focus(); return false; } if(document.form.city.value == ""){ alert("Please enter city." ); document.form.city.focus(); return false; } return true; } </script> <form name="form" method="post" onsubmit="return validate();" action="insertdata.jsp"> <table> <tr><td>Enter First Name</td><td><input type="text" name="fname"></td></tr> <tr><td>Enter Last Name</td><td><input type="text" name="lname"></td></tr> <tr><td>Enter User Name</td><td><input type="text" name="uname"></td></tr> <tr><td>Enter Password</td><td><input type="password" name="pass"></td></tr> <tr><td>Enter Address</td><td><input type="text" name="address"></td></tr> <tr><td>Enter Contact No</td><td><input type="text" name="contact"></td></tr> <tr><td>Enter Email</td><td><input type="text" name="email"></td></tr> <tr><td></td><td><input type="submit" value="Add" name="button"></td></tr> </table> </form> </html>
4)insertdata.jsp:
<%@page import="java.sql.*,java.util.*"%> <table> <% String uname=request.getParameter("uname"); String fname=request.getParameter("fname"); String lname=request.getParameter("lname"); String pass=request.getParameter("pass"); String address=request.getParameter("address"); int contact=Integer.parseInt(request.getParameter("contact")); String email=request.getParameter("email"); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st=con.createStatement(); int i=st.executeUpdate("insert into login(username,password,firstname,lastname,address,contactNo,email) values('"+uname+"','"+pass+"','"+fname+"','"+lname+"','"+address+"',"+contact+",'"+email+"')"); out.println("Data is successfully inserted into database."); ResultSet rs=st.executeQuery("Select * from login"); if(rs.last()){ %> <tr><td>User Name</td><td><input type="text" value="<%=rs.getString("username")%>"></td></tr> <tr><td>First Name</td><td><input type="text" value="<%=rs.getString("firstname")%>"></td></tr> <tr><td>Last Name</td><td><input type="text" value="<%=rs.getString("lastname")%>"></td></tr> <tr><td>Address</td><td><input type="text" value="<%=rs.getString("address")%>"></td></tr> <tr><td>Contact No</td><td><input type="text" value="<%=rs.getInt("contactNo")%>"></td></tr> <tr><td>Email</td><td><input type="text" value="<%=rs.getString("email")%>"></td></tr> <% } con.close(); } catch(Exception e){ System.out.println(e); } %> </table>
really helpful.........thanxxx....:)
here after once insertion takes place no another insertion is going on tell me the reason please
Ads