JSP Implementation User Login Example

Source: Internet
Author: User

Business description

The user enters the user name password login on the login.jsp page:

If the user name is Xingoo, the password is 123, then jump to the successful interface login_success.jsp, and display the user login name;

If the user name password is incorrect, jump to the failed interface login_failure.jspand prompt to return to the login screen.

login.jsp Code
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User Login</title></Head><Body>    <H1>User Login</H1>    <HR>    <formname= "RegForm"Action= "dologin.jsp"Method= "POST">        <Table>            <TR>                <TD>Username</TD>                <TD><inputtype= "text"name= "username"/></TD>            </TR>            <TR>                <TD>Password</TD>                <TD><inputtype= "Password"name= "Password"/></TD>            </TR>            <TR>                <TDcolspan= "2"><inputtype= "Submit"value= "Submit"/></TD>            </TR>        </Table>    </form></Body></HTML>
DOLOGIN.JSP Processing Code
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "Utf-8"%><%String username= ""; String Password= ""; Request.setcharacterencoding ("Utf-8"); Username= Request.getparameter ("username"); Password= Request.getparameter ("Password"); if("Xingoo". Equals (username) && "123". Equals (password)) {Session.setattribute ("Loginuser", username); Request.getrequestdispatcher ("Login_success.jsp"). Forward (Request,response); }Else{response.sendredirect ("Login_failure.jsp"); }%>
LOGIN_SUCCESS.JSP User Login Successful interface
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User Login</title></Head><Body>    <H1>User Login</H1>    <HR>you are welcome!<%=Session.getattribute ("Loginuser") %></Body></HTML>
LOGIN_FAILURE.JSP User Login Failure interface
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User Login</title></Head><Body>    <H1>User Login</H1>    <HR>Login failed!<ahref= "login.jsp">Back to Login</a></Body></HTML>

JSP Implementation User Login Example

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.