Java Web module of login

Source: Internet
Author: User

Reffer to the Book<java Web integration Development King return;.

It ' s JSP page.

Offer the values of username and password to servlet.

Then save the session.

The code is simple.

Easy to read.

Except the mylogin.jsp,also need a JavaBean Person.java.

<%@ page language= "java" pageencoding= "UTF-8"%><jsp:directive.pageImport= "Com.helloweenvsfei.sessionWeb.bean.Person"/><jsp:directive.pageImport= "Java.text.SimpleDateFormat"/><jsp:directive.pageImport= "Java.text.DateFormat"/><jsp:directive.pageImport= "Java.util.Date"/><%!DateFormat DateFormat=NewSimpleDateFormat ("Yyyy-mm-dd");%><%response.setcharacterencoding ("UTF-8"); person[] Persons= {        NewPerson ("Linghuchong", "Linghuchong", Dateformat.parse ("1982-01-01"))),         NewPerson ("Hello Kitty", "Hellokitty", Dateformat.parse, "1984-02-25")),        NewPerson ("renyingying", "renyingying", Dateformat.parse ("1994-09-12"))),    }; String message= ""; if(Request.getmethod (). Equals ("POST"))    {         for(person person:persons) {if(Person.getname (). Equalsignorecase (Request.getparameter ("username"))                    && Person.getpassword (). Equals (Request.getparameter ("Password")) {Session.setattribute ("Person", person); Session.setattribute ("Logintime",NewDate ()); Response.sendredirect (Request.getcontextpath ()+ "/welcome.jsp"); return; }        }        //Login FailedMessage = "Wrong username or Pwd,login failed"; }%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >if(! message.equals (""))            {%> <tr> <td></td> <td>login failed!</td>                </tr> <%}%> <tr> <td>username:</td> <td><input type= "text" name= "username" style= "width:200px; "> </td> </tr> <td>password:</td> <td>&lt Input type= "password" name= "password" style= "width:200px";  "> </td> <tr> <td></td> <td><input Type= "Submit" value= "Login"class= "button" > </td> </tr> </table> </form>Hello Kitty, Hellokitty</body>

Java Web module of login

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.