The system frame diagram is as follows:
Three documents are as follows:
Login interface
/** *//**
* @ (#) Login.java
*
*
* @author shiyi05
* @version 1.00 2008/5/10
*/
Package Com.rao;
Import javax.servlet.http.*;
Import java.io.*;
public class Login extends HttpServlet
{
Public Login ()
{
}
Handling GET Requests
public void doget (HttpServletRequest req,httpservletresponse Res)
{
Try
{
Chinese garbled
Res.setcontenttype ("text/html; CHARSET=GBK ");
PrintWriter Pw=res.getwriter ();
Return to login interface
Pw.println ("Pw.println ("<body>");
PW.PRINTLN ("Pw.println ("<form action=logincl method=post>");
Pw.println ("Username: <input type=text name=username><br>");
Pw.println ("Password: <input type=password name=passwd><br>");
Pw.println ("<input type=submit value=loing><br>");
Pw.println ("</body>");
Pw.println ("}
catch (Exception ex)
{
Ex.printstacktrace ();
}
}
public void DoPost (HttpServletRequest req,httpservletresponse Res)
{
This.doget (Req,res);
}
}
User authentication
/** *//**
* @ (#) Logincl.java
*
*
* @author shiyi05
* @version 1.00 2008/5/10
*/
Package Com.rao;
Import javax.servlet.http.*;
Import java.io.*;
public class Logincl extends HttpServlet
{
Public Logincl ()
{
}
Handling GET Requests
public void doget (HttpServletRequest req,httpservletresponse Res)
{
Try
{
Chinese garbled
Res.setcontenttype ("text/html; CHARSET=GBK ");
Receive user name and password
String U=req.getparameter ("username");
String p=req.getparameter ("passwd");
Verify
if (u.equals ("sp") && P.equals ("123"))
{
Legal
Res.sendredirect ("Welcome");
}
Else
{
Not legal
Res.sendredirect ("Login");
}
}
catch (Exception ex)
{
Ex.printstacktrace ();
}
}
public void DoPost (HttpServletRequest req,httpservletresponse Res)
{
This.doget (Req,res);
}
}
Welcome interface
/** *//** *//** *//**
* @ (#) Welcome.java
*
*
* @author shiyi05
* @version 1.00 2008/5/10
*/
Package Com.rao;
Import javax.servlet.http.*;
Import java.io.*;
public class Welcome extends HttpServlet
{
Public Welcome ()
{
}
Handling GET Requests
public void doget (HttpServletRequest req,httpservletresponse Res)
{
Try
{
Chinese garbled
Res.setcontenttype ("text/html; CHARSET=GBK ");
PrintWriter Pw=res.getwriter ();
Return to login interface
Pw.println ("Pw.println ("<body>");
Pw.println ("Pw.println ("</body>");
Pw.println ("}
catch (Exception ex)
{
Ex.printstacktrace ();
}
}
public void DoPost (HttpServletRequest req,httpservletresponse Res)
{
This.doget (Req,res);
}
}