input.jsp(01)

本文介绍了一个用户添加表单的实现方式,其中包括对用户代码、用户名称和密码等字段的有效性验证。用户代码需至少四位且首字符必须是字母,用户名称不可为空,密码长度至少六位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>添加用户</title>
<link rel="stylesheet" href="../style/drp.css">
<script src="../script/client_validate.js"></script>
<script type="text/javascript">

function addUser() {
if (document.getElementById("userId").value.length <4) {
alert("用户代码不能小于4个字符!");
document.getElementById("userId").focus();
return;
}
var firstChar = document.getElementById("userId").value.charAt(0);

if (!(firstChar >= 'a' && firstChar <='z')) {
alert("用户代码首字符必须为字母");
document.getElementById("userId").focus();
return;
}
if(document.getElementById("userName").value == "") {
alert("用户名称不能为空!");
document.getElementById("userName").focus();
return;
}
if (document.getElementById("password").value.length <6) {
alert("输入的密码不能小于6位字符");
document.getElementById("password").focus();
return;
}
with (document.getElementById("userForm")) {
method = "post";
action = "add.do";
submit();
}
}

function goBack() {
window.self.location ="list.do"
}

function init() {
document.userForm.userId.focus();
}
</script>
</head>

<body class="body1">
<form name="userForm" target="_self" id="userForm">
<div align="center">
<table width="95%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
 
</td>
</tr>
</table>
<table width="95%" border="0" cellspacing="0" cellpadding="0"
height="25">
<tr>
<td width="522" class="p1" height="25" nowrap>
<img src="../images/mark_arrow_03.gif" width="14" height="14">
 
<b>系统管理>>用户维护>>添加</b>
</td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<table width="95%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="22%" height="29">
<div align="right">
<font color="#FF0000">*</font>用户代码: 
</div>
</td>
<td width="78%">
<input name="userId" type="text" class="text1" id="userId"
size="10" maxlength="10">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>用户名称: 
</div>
</td>
<td>
<input name="userName" type="text" class="text1" id="userName"
size="20" maxlength="20">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>密码: 
</div>
</td>
<td>
<label>
<input name="password" type="password" class="text1"
id="password" size="20" maxlength="20">
</label>
</td>
</tr>
<tr>
<td height="26">
<div align="right">
联系电话: 
</div>
</td>
<td>
<input name="contactTel" type="text" class="text1"
id="contactTel" size="20" maxlength="20">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
email: 
</div>
</td>
<td>
<input name="email" type="text" class="text1" id="email"
size="20" maxlength="20">
</td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" class="button1" type="button" id="btnAdd"
value="添加" onClick="addUser()">
    
<input name="btnBack" class="button1" type="button" id="btnBack"
value="返回" onclick="goBack()" />
</div>
</div>
</form>
</body>
</html>
编写JSP(Java Server Pages)页面是为了在Web应用中动态生成HTML内容。这里我会简单描述如何创建`input.jsp`和`result.jsp`的基本结构,它们通常用于用户输入数据和显示结果的场景。 **input.jsp** (用户输入页面): 这个页面通常是表单形式,让访问者可以填写信息。例如: ```jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>用户输入</title> </head> <body> <form action="result.jsp" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br><br> <label for="email">邮箱:</label> <input type="email" id="email" name="email"><br><br> <input type="submit" value="提交"> </form> </body> </html> ``` 在这个例子中,表单的`action`属性指向`result.jsp`,`method`设为`post`表示通过POST请求发送数据。 **result.jsp** (处理并显示结果的页面): 当用户提交了`input.jsp`的数据后,`result.jsp`会接收到这些数据并在服务器端处理。示例展示如何获取并显示用户输入的信息: ```jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>结果展示</title> </head> <body> <% String username = request.getParameter("username"); String email = request.getParameter("email"); out.println("<h2>用户信息:</h2>"); out.println("<p>用户名: " + username + "</p>"); out.println("<p>Email: " + email + "</p>"); %> </body> </html> ``` 在这里,我们使用`request.getParameter()`方法从HTTP请求中获取用户提供的值,并用`out.println()`将其打印到页面上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值