使用JavaWeb实现企业邮箱登录验证功能
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML > <html> <head> <base href="<%=basePath%>"> <title>邮箱登录页面</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <h3>邮箱登录</h3> <hr> <form action="lucky.jsp" method="post"> 用户名:<input type="text" name="uname"><br><br> 密 码: <input type="password" name="upwd"><br><br> <input type="submit" value="登录"> <input type="reset" value="清空"> </form> </body> </html>
doindex.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <title>邮箱处理页面</title> </head> <% //设置编码 request.setCharacterEncoding("UTF-8"); String uname=request.getParameter("uname"); String pwd=request.getParameter("upwd"); if(uname.equals("lucky")&&pwd.equals("123456")){ //成功 out.print("你好,"+uname+"!"); request.getRequestDispatcher("lucky.jsp").forward(request, response); }else{ response.sendRedirect("index.jsp"); //request.getRequestDispatcher("index.jsp").forward(request, response); } %>
lucky.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <title>邮箱验证成功页面</title> <h1>验证成功!</h1> <h2>你好, <% String name=request.getParameter("uname"); String pwd=request.getParameter("upwd"); if(!name.equals("lucky")&&!pwd.equals("123456")){ response.sendRedirect("index.jsp"); } out.print(name); %> </h2>
本文链接:https://www.kkkliao.cn/?id=21 转载需授权!
版权声明:本文由廖万里的博客发布,如需转载请注明出处。