jsp写的登录页面用户名和密码

<html>


<center>
<p>
<head><h1>登录窗口</h1></head>
</p>
<body bgcolor="gray">

<form name = "login"  method = "POST" action= "http://blog.csdn.net/jin_guang" οnsubmit="return

checkform();" align = "center" >
<table align="center">
<tr><td>
用户名:
</td>
<td><input type="text" name="username">
</td></tr>

<tr><td>
密 码:
</td>
<td><input type="password" name="password">
</td></tr>

<tr>
<td></td>
<br><td align="center">
<input type="submit"  value="登陆">
</td></tr>
</form>

<script type="text/javascript">
function checkform()
{
if(login.username.value.length != 6 )
{
alert("用户名不正确!");
return false;
}
else(document.getElementById('password').value=='')
{
alert("密码不能为空!");
return false;
}
}
</script>
</body>
</center>
</html>


  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,针对你的问题,我可以给出以下实现方案: 1. 在 JSP 页面添加表单,包含登录用户名密码验证码的输入框: ```jsp <form action="login.jsp" method="post"> <label for="username">用户名</label> <input type="text" name="username" id="username"> <br> <label for="password">密码</label> <input type="password" name="password" id="password"> <br> <label for="captcha">验证码</label> <input type="text" name="captcha" id="captcha"> <img src="captcha.jsp" alt="验证码"> <br> <input type="submit" value="登录"> </form> ``` 其验证码的图片由 captcha.jsp 页面生成,后面会讲到。 2. 在 login.jsp 页面获取表单提交的数据,并进行合法性检查: ```jsp <% String username = request.getParameter("username"); String password = request.getParameter("password"); String captcha = request.getParameter("captcha"); // 进行数据合法性检查 if (username == null || username.trim().length() == 0 || password == null || password.trim().length() == 0 || captcha == null || captcha.trim().length() == 0) { out.println("用户名密码验证码不能为空"); } else { // 进行登录验证 // ... } %> ``` 这里我们要求用户名密码验证码都不能为空,否则提示用户输入不能为空。 3. 在 captcha.jsp 页面生成验证码图片,并将验证码保存到 session : ```jsp <% // 生成验证码字符串 String captcha = generateCaptcha(); // 将验证码保存到 session HttpSession session = request.getSession(); session.setAttribute("captcha", captcha); // 生成验证码图片 BufferedImage image = generateCaptchaImage(captcha); OutputStream out = response.getOutputStream(); ImageIO.write(image, "JPEG", out); out.close(); %> ``` 这里我们要求验证码必须是随机生成的,并且要将验证码保存到 session ,以便后续的验证。 4. 在 login.jsp 页面输入验证码进行验证: ```jsp <% String username = request.getParameter("username"); String password = request.getParameter("password"); String captcha = request.getParameter("captcha"); // 获取保存在 session 验证码 HttpSession session = request.getSession(); String savedCaptcha = (String) session.getAttribute("captcha"); // 进行验证码的验证 if (!captcha.equalsIgnoreCase(savedCaptcha)) { out.println("验证码错误"); } else { // 进行登录验证 // ... } %> ``` 这里我们要求用户输入验证码必须和保存在 session 验证码一致。 以上是一些简单的 JSP 实现登录用户名密码验证码检验的方案,具体的实现还需要根据具体的需求进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值