Code for implementing user login Interaction Using j2e-j2ee

Source: Internet
Author: User

Server Code :
Loginservlet:
Package com; Copy code The Code is as follows: Import java. Io. bytearrayoutputstream;
Import java. Io. dataoutputstream;
Import java. Io. ioexception;
Import java. Io. outputstream;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
/***//********************************** **************************************** *****
*
* @ Author zdw
*
*/
@ Suppresswarnings ("serial ")
Public class loginservlet extends httpservlet
{
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception
{
This. dopost (request, response );
}
Public void dopost (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception
{
// Obtain the data (username and password) passed in by the client)
String username = request. getparameter ("username ");
String Password = request. getparameter ("password ");
// Construct the output stream
Bytearrayoutputstream baos = new bytearrayoutputstream ();
Dataoutputstream dos = new dataoutputstream (baos );
// Logical operation (write your logical judgment here)
If ("zdw". Equals (username) & "admin". Equals (password ))
{
// Response data
Dos. writeutf ("true ");
} Else
{
// Response data
Dos. writeutf ("false ");
}
//
Byte [] DATA = baos. tobytearray ();
// Set Server Response parameters
Response. setstatus (httpservletresponse. SC _ OK );
Response. setcontentlength (data. Length );
Response. setcontenttype ("application/octet-stream ");
Outputstream OS = response. getoutputstream ();
OS. Write (data );
OS. Close ();
}
}

Source code download: Click here to download
Note that this project is a myeclipse project. You must install wtk and tomcat to run this project normally.Program.
Logon diagram:

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.