JSP built-in object Job 1-User Login

Source: Internet
Author: User

Title: Write a JSP program to implement user login, when the user entered a user name or password error, the page is redirected to the error prompt, and after the page is displayed for 30 seconds, automatically return to the user login page.

1. User Login Page

1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Login Page</title>8 </Head>9 <Body>Ten <formname= "Form1"Action= "denglu.jsp"> One  A User name: - <inputtype= "text"name= "User"><BR> - Password: the <inputtype= "Password"name= "PW"><BR> - <inputtype= "Submit"name= "BT"value= "Submit">  -  - </form> +  - </Body> + </HTML>

2, Login Processing page

1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8" %>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Login Processing Page</title>8 </Head>9 <Body>Ten <% One //the correct user name password A StringUser1= "123"; - StringPW1= "123"; - //get the user name password you entered the StringUser=Request.getparameter ("User"); - StringPW=Request.getparameter ("PW"); - //determine if the user name password is correct - if(User.equals (user1)&pw.equals (PW1)) + { - Out.print ("Login Successful"); + } A Else at { - Response.sendredirect ("error.jsp"); - } - %> - </Body> - </HTML>

3, Error Tip page

1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8" %>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Error Handling page</title>8 </Head>9 <Body>Ten the user name or password is wrong, please try again later. One <% A //REDIRECT to login page after 30 seconds - Response.setheader ("Refresh","30; URL = index.jsp"); - %> the </Body> - </HTML>

JSP built-in object Job 1-User 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.