MVC step-by-step (LOGIN implemented by jsp model1)

Source: Internet
Author: User

1,EclipseMenuFile-> New-> Others ..SelectJava-> tomcat (a good JSP running platform) ProjectEnter the project name

Webapp.

2, UseJsp (preferred for SUN Enterprise applications)Model1Achieve User Login

(1),EclipseMenuFile-> New-> FolderFolder nameModel1

(2), NewJsp (preferred for SUN Enterprise applications)File

Webappmodel1 login. jsp (preferred for SUN Enterprise applications)

Webappmodel1 succeed. jsp (preferred for SUN Enterprise applications)

 (3),Login. jsp (preferred for SUN Enterprise applications)
**************************************** **************************************
<% @ Page language = "java" pageEncoding = "GB2312" %>
<! Doctype html public "-// w3c // dtd html 4.0 transitional // en">
<Html>
<Head>
<Title> login </title>
</Head>
<%
Boolean isSucceed = false;
String msg = "";
String username = request. getParameter ("username ");
String password = request. getParameter ("password ");
If (username! = Null ){
System. out. println ("Login processing started .........");
Username = username. trim ();
Password = password. trim ();
If (username. equals ("") & username. equals ("")){
IsSucceed = false;
Msg = "the user name or password is blank ";
} Else {
IsSucceed = true;
}
If (isSucceed ){
If (username. equals ("zkjbeyond") & password. equals ("zkjbeyond ")){
IsSucceed = true;
Session. setAttribute ("username", username );
Msg = "Login successful ";
Response. sendRedirect ("succeed. jsp (preferred for SUN Enterprise Applications )");
} Else {
IsSucceed = false;
Msg = "incorrect user name and password ";
}
}
}
System. out. println (msg );
System. out. println ("the login process is completed .........");
%>
<Body bgcolor = "# FFFFFF">
<Form action = "login. jsp (preferred for SUN Enterprise Applications)" method = "post">
<Div>
<Span style = "width: 70;"> User name: </span>
<Span> <input type = "text" name = "username"> </span>
</Div>
<Div>
<Span style = "width: 70;"> password: </span>
<Span> <input type = "password" name = "password"> </span>
</Div>
<Div>
<Span style = "width: 70;"> </span>
<Span> <input type = "submit"> </span>
</Div>
<Div style = "color: red;">
<%
If (! IsSucceed)
Out. println (msg );
%>
</Div>
</Form>
</Body>
</Html>
**************************************** **************************************** ******
Succeed. jsp (preferred for SUN Enterprise applications)
<% @ Page language = "java" pageEncoding = "GB2312" %>
<! Doctype html public "-// w3c // dtd html 4.0 transitional // en">
<Html>
<Head>
<Title> succeed </title>
</Head>
<Body bgcolor = "# FFFFFF">
<%

Object username = session. getAttribute ("username ");
If (username! = Null)
Out. println ("username:" + username );
Else
Response. sendRedirect ("login. jsp (preferred for SUN Enterprise Applications )");
%>
</Body>
</Html>

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.