Hi..Sir, I want to create a prog. using jdbc,servlets.i.e. when i enter username,password from html that username,password stored in database using servlets. Please be forward.thank you.

Questions by janandababu

Showing Answers 1 - 1 of 1 Answers

Guest

  • Jan 1st, 2006
 

hi,

Here i'm giving one ex. prog.  to solve ur problem.

                       After entering Username and Password in Main.html will call the servlet( by seeing lookup in web.xml )Post method,so that it gets the previous form data and stores that in backend by using jdbc code.

Main.html

<HTML>
<HEAD>
<TITLE> U can Logon Here............................................. </TITLE>
</HEAD>
<BODY bgcolor=#CCCCCC>
<center>
<FORM name=f1 METHOD=POST ACTION="Register">
<font size=3 color= #FFFFFF><b>UserName :</b></font><b><input type=text name=huname ><br><br>
<font size=3 color= #FFFFFF><b>Password :</b></font><input type=password size=10 name=hpwd>
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type=submit name=submit value=Signin>
</FORM>
<form method=get name=f2 action="forgot">
</form>
</center>
</BODY>
</HTML>

Register.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class Register extends HttpServlet
{
 public void init(ServletConfig sc)
 {
  try
  {
   super.init(sc);
   ServletContext scon=sc.getServletContext();
   cls=scon.getInitParameter("class");
   conn=scon.getInitParameter("con");
   uname=scon.getInitParameter("user");
   pwd=scon.getInitParameter("pwd");
   Class.forName(cls);
   con=DriverManager.getConnection(conn,uname,pwd);
  }
  catch(Exception e)
  {
   System.out.println("error while connection "+e);
  }
 }
    public void doPost(HttpServletRequest req,HttpServletResponse res)throws       ServletException,IOException
  {
  try
  {    String suname=req.getParameter("huname");
    String spwd=req.getParameter("hpwd");
       st=con.createStatement();
      int n=st.executeUpdate("insert into Userinfo values'"huname+"','"+spwd+"')");
      res.setContentType("text/html");
   &

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions