Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc servlet

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone
i am new to java.i have a query regarding login in my project
when user is registered member of my site and he will login how
the comparison for matching the existing userid and password from jdbc will be done by using servlets and jdbc?
please i need help.
 
Raukutam Sandeep
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rahul,

in the service method of the servlet, using getParameter method of ServletRequest u can retrieve the username and password and compare to any value.
Here is a sample example:
//program for verifying username and password
//entered by the user
import javax.servlet.*;
public class signin extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)
{
try
{
String username=req.getParameter("uname");
String password=req.getParameter("pwd");
ServletOutputStream sos=res.getOutputStream();
sos.println("<html>");
if((username.equals("admin")) && (password.equals("rsandeep")))
{
sos.println("<head><title>SanMail</title></head>");
sos.println("<body>");
sos.println("<center>Login Succesful</center>");
sos.println("
");
sos.println("Your username: "+username+"");
sos.println("Your Password: "+password+"");
sos.println("</body>");
}
else
{
sos.println("<head><title>Verify your username and password</title></head>");
sos.println("<body>");
sos.println("<center>Login Unsuccesful. Try again, by clicking your browser's back button.</center>");
sos.println("</body>");
}
sos.println("</html>");
}
catch(Exception e)
{
e.printStackTrace();
}
} // end of service
} // end of class
Here i have verified the username and password manually, u can do it with JDBC also.
first retrieve the username and password using select query and store it in a resultset, and using getString method of resultset store the username and password in String variables and then u can compare as above.
try it and get back!!!
Good luck..
regds,
Sandeep.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic