56jsp登录案例
鏈接:https://pan.baidu.com/s/1W4UYInbsm17V9_2rFLNGFg
提取碼:c5g5
復(fù)制這段內(nèi)容后打開百度網(wǎng)盤手機(jī)App,操作更方便哦
login.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html><head><!-- Page title --><title>Login</title><!-- End of Page title --><!-- Libraries --><link type="text/css" href="css/login.css" rel="stylesheet" /> <link type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.html" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script><script type="text/javascript" src="js/easyTooltip.js"></script><script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script><!-- End of Libraries --> </head><body><div id="container"><div class="logo"><a href="#"><img src="assets/logo.png" alt="" /></a></div><div id="box"><form action="dologin.jsp" method="post"><p class="main"><label>用戶名: </label><input name="username" value="" /> <label>密碼: </label><input type="password" name="password" value=""> </p><p class="space"><input type="submit" value="登錄" class="login" style="cursor: pointer;"/></p></form></div></div></body> </html>dologin.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";String username ="";String password ="";request.setCharacterEncoding("utf-8");//防止中文亂碼username = request.getParameter("username");password = request.getParameter("password");//如果用戶和密碼都等于admin,則登錄成功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_failure.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html><head><!-- Page title --><title>imooc - Login</title><!-- End of Page title --><!-- Libraries --><link type="text/css" href="css/login.css" rel="stylesheet" /> <link type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.html" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script><script type="text/javascript" src="js/easyTooltip.js"></script><script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script><!-- End of Libraries --> </head><body><div id="container"><div class="logo"><a href="#"><img src="assets/logo.png" alt="" /></a></div><div id="box">登錄失敗!請檢查用戶或者密碼!<br><a href="login.jsp">返回登錄</a> </div></div></body> </html>login_success.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html><head><!-- Page title --><title>imooc - Login</title><!-- End of Page title --><!-- Libraries --><link type="text/css" href="css/login.css" rel="stylesheet" /> <link type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.html" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script><script type="text/javascript" src="js/easyTooltip.js"></script><script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script><!-- End of Libraries --> </head><body><div id="container"><div class="logo"><a href="#"><img src="assets/logo.png" alt="" /></a></div><div id="box"><% String loginUser = "";if(session.getAttribute("loginUser")!=null){loginUser = session.getAttribute("loginUser").toString();}%>歡迎您<font color="red"><%=loginUser%></font>,登錄成功!</div></div></body> </html>運(yùn)行結(jié)果
主界面
輸入賬號(hào)admin? 密碼admin
輸入錯(cuò)誤
源碼可直接下載,學(xué)習(xí)jsp的朋友有興趣可以了解一下。
總結(jié)
- 上一篇: Linuxcurl命令参数详解
- 下一篇: 登录页面实现