aspose file tools*
The moose likes JDBC and the fly likes jdbc servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc servlet" Watch "jdbc servlet" New topic
Author

jdbc servlet

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 15, 2000
Posts: 61
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc servlet