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