m0_53710723 2021-01-27 18:46 采纳率: 0%
浏览 269

jsp注册页面用户名密码为空也能提交怎么办?

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP</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">
	-->
  <body>
  <script str="Scripts/JScript.js"type="text/javascript">
		function addcheck(){
			var username1=document.getElementById("username").value;
			var password1=document.getElementById("password").value;
			var newword1=document.getElementById("newword").value;
			if(username1 == " "){
				alert("用户名不能为空!");
				//document.getElementById("username").focus();  
				return false;
                }
			if(password1 == " "){
				alert("密码不能为空!");
				 //document.getElementById("password").focus();
				 return false;
				 }
			if(password1 != newword1){
				alert("两次输入密码不相同!");
				 //document.getElementById("newword").focus();
				 return false;
				 }
			return true;
		}
	</script>
    <center>
	<font face="楷体" size="6" color="#000">注册界面</font>
	<form action = "checkRegister.jsp" method = "post" onsubmit = "return addcheck()">
  	<table width="300" height = "180" border="5" bordercolor="#A0A0A0">
  	  <tr>
		<th>用户名:</th>
		<td><input type="text" name="username" value="输入16个字符以内" maxlength = "16" onfocus = "if(this.value == '输入16个字符以内') this.value =''"></td>
 	  </tr>
 	  <tr>
 		<th>输入密码:</th>
 		<td><input type="text" name="password" value="输入20个字符以内" maxlength = "20" onfocus = "if(this.value == '输入20个字符以内') this.value =''"></td>
 	  </tr>
 	  <tr>
 		<th>确认密码:</th>
 		<td><input type="text" name="newword" value="重新输入密码" maxlength = "20" onfocus = "if(this.value == '重新输入密码') this.value =''"></td>
 	  </tr>
	  <tr>
 		<td colspan = "2" align = "center">
 		  <input type="submit" value="注  册" id="submit"/>    
 		  <input type="reset" value="重  置">
 		</td>
	  </tr>
	</table>
    </form>
    </center>
  </body>
</html>

这个程序运行时输入用户名为空,密码为空,和两次密码不一样的时候也都能提交信息并成功注册,信息检查的功能没有实现。有哪位大佬知道是什么地方出现问题了吗?能帮忙解决一下吗?非常感谢!!!

  • 写回答

3条回答 默认 最新

  • 木蓝茶陌*_* 2021-01-27 19:10
    关注

    1.通过document.getElementById()来获取dom元素,但是你没有给元素id

    2.文本框提示文本用的是placeholder="输入16个字符以内"

    3.判断输入字符串是否为空,if(username1 == ""){ },引号之间没有空格

    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services