首页 > 技术文章 > login

huangliping 2016-12-02 10:23 原文

整理总结视频与他人的。。。

 

1、<input style="cursor:pointer">:手型鼠标
2、总结JSP页面传值:
   会用到三个JSP页面:login.jsp 、login_suceess.jsp、login_failure.jsp、dologin.jsp.
   在login.jsp:代码为:
   <%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login</title>
</head>
<body>
<center>
    <div id="container">
        <div class="logo">
            <a href="#"><img src="images/chunse.jpg" alt="" width="100%" height="5%"> </image> </a>
        </div>
        <div id="box">
        <form action="dologin.jsp" method="post">
        <p class="main">
        <label>用户名:</label>
        <input name="username" value=""/>
        <label>密码:</label>
        <input name="password" type="password" value=""/>
        </p>
        <p class="space">
        <input type="submit" value="登陆" class="login" style="cursor:pointer" float="right">
        </p>
        </form>

    </div>
</div>
</center>
</body>
</html>

dologin.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    /* String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
     */String username = "";
    String password = "";
    username = request.getParameter("username");
    password = request.getParameter("password");
    if ("admin".equals(username) && "admin".equals(password)) {
        session.setAttribute("loginUser", username);
        request.getRequestDispatcher("login_success.jsp").forward(request, response);
    }
    else
    {
        response.sendRedirect("login_failure.jsp");
    }
%>

login_success.jsp:
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login</title>
</head>
<body>
<div id="container">
        <div class="logo">
            <a href="#"><img src="images/chunse.jpg" alt="" width="100%" height="5%"> </a>
        </div>
        <div id="box">
        <%-- <% String loginUser="";
        if(session.getAttribute("loginUser")!=null)
        {
            loginUser=session.getAttribute("loginUser").toString();
        }
        %> --%>
        
        欢迎您,<font color="red"><%=session.getAttribute("loginUser")%></font>,登陆成功!

    </div>
</div>
</body>
</html>


login_failure.jsp:
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login</title>
</head>
<body>
<div id="container">
        <div class="logo">
            <a href="#"><img src="images/chunse.jpg" alt="" width="100%" height="5%"> </image> </a>
        </div>
        <div id="box">
        登陆失败,请检查用户名或密码!
        <a href="login.jsp">返回登陆</a>

    </div>
</div>
</body>
</html>

总结:login.jsp中获取用户输入的用户名与密码,通过form表单传递到dologin.jsp中;在dologin.jsp中进行验证,选择进入不同的jsp页面(利用到了重定向);

推荐阅读