编写程序reg.htm和reg.jsp,做一用户注册界面,注册信息包括:用户名,年龄,性别。然后提交到reg.jsp进行注册检验,若用户名为admin,就提示“欢迎你,管理员”,否则,显示“注册成功”并显示出注册信息。(20分)
时间: 2024-03-23 11:41:48 浏览: 27
很抱歉,我是一个语言模型,并不能编写程序。不过,我可以提供一个简单的HTML和JSP代码示例,供你参考:
reg.htm
```html
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h1>User Registration</h1>
<form action="reg.jsp" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age"><br><br>
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>
```
reg.jsp
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Registration Result</title>
</head>
<body>
<h1>Registration Result</h1>
<%
String username = request.getParameter("username");
int age = Integer.parseInt(request.getParameter("age"));
String gender = request.getParameter("gender");
if(username.equals("admin")) {
out.println("Welcome, administrator!");
} else {
out.println("Registration successful<br>");
out.println("Username: " + username + "<br>");
out.println("Age: " + age + "<br>");
out.println("Gender: " + gender + "<br>");
}
%>
</body>
</html>
```
这个示例中,reg.htm是一个HTML表单页面,其中包含了用户名、年龄和性别的输入框和一个提交按钮。当用户填写完信息后,点击提交按钮会将表单数据提交到reg.jsp进行处理。
在reg.jsp中,我们使用了JSP标签和Java代码来处理表单数据。首先,我们从request对象中获取用户名、年龄和性别的值。然后,我们通过一个if语句来判断用户名是否为admin,如果是,则显示欢迎管理员的信息;否则,显示注册成功并显示出用户的注册信息。最后,我们使用out对象将处理结果输出到HTML页面上。
请注意,这只是一个简单的示例程序,实际应用中还需要进行更多的注册检验和安全性处理。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)