使用JSP实现用户登录验证功能

使用JSP实现用户登录验证功能

创建index.jsp

代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
     String str=request.getParameter("username");
     String pwd=request.getParameter("pwd");
     if(null!=str){
    	 if(str.equals("YBD")&&pwd.equals("666")){
    		 out.println("您好,YBD!");
    	 }else{
    		 out.println("您输入的账号密码有误,请重新输入!");
    	 }
     }
%>      
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="index.jsp" method="post">
                  账号:<input type="text" name="username"/> <br>
                  密码:<input type="password" name="pwd"/> <br>   
     <input type="submit" value="登录"/>                     
    </form>         
</body>
</html>

验证成功:
在这里插入图片描述
验证失败:
在这里插入图片描述

这是上机实验(第三次)

发布了26 篇原创文章 · 获赞 61 · 访问量 9238

猜你喜欢

转载自blog.csdn.net/HYD696/article/details/104820328