JSP implementation of a simple user login system

Source: Internet
Author: User

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);
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.