设计一个用户注册的功能,要求如下: 1)注册页面应包含基本的文本框、单选按钮、复选框、选择栏等元素,具体要求除提交按钮、重置按钮外,页面至少包含三种其他html控件1)intput.jsp中包含一个表单 2)点击注册按钮时,要求对用户名(昵称)进行判空,如果用户未填写用户名(昵称),需要提示“请输入用户名!”; 3)若用户输入正确,请将注册信息展示在另外一个页面上; 4)在展示信息的页面上添加“修改(用户名)昵称”超链接,点击超链接进入修改用户名(昵称)的页面,并在该页面上显示原昵称,用户修改昵称后,点击提交按钮,跳转到新页面展示修改后的昵称。 1)intput.jsp中包含一个表单 2)如果用户没有输入昵称,跳转回 input.jsp 页面并提示用户信息“昵称不能为空,请重新输入!” 3)如果用户输入昵称合法,则打印出所有注册信息 4)在 updateForm.jsp 页面中创建表单 修改成功显示如下信息
时间: 2024-02-18 11:05:38 浏览: 101
好的,我已经理解你的要求了。以下是一个简单的示例代码:
1. input.jsp 页面:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>User Registration</title>
</head>
<body>
<h1>User Registration</h1>
<form action="register.jsp" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female" required>
<label for="female">Female</label><br><br>
<label for="hobby">Hobby:</label>
<input type="checkbox" id="reading" name="hobby" value="reading">
<label for="reading">Reading</label>
<input type="checkbox" id="music" name="hobby" value="music">
<label for="music">Music</label>
<input type="checkbox" id="sports" name="hobby" value="sports">
<label for="sports">Sports</label><br><br>
<label for="country">Country:</label>
<select id="country" name="country" required>
<option value="">Please select</option>
<option value="China">China</option>
<option value="USA">USA</option>
<option value="Japan">Japan</option>
</select><br><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
```
2. register.jsp 页面:
```html
<%
String username = request.getParameter("username");
String gender = request.getParameter("gender");
String[] hobbies = request.getParameterValues("hobby");
String country = request.getParameter("country");
if(username == null || username.isEmpty()) {
response.sendRedirect("input.jsp?msg=Please enter username!");
} else {
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Registration Information</title>
</head>
<body>
<h1>Registration Information</h1>
<p>Username: <%= username %></p>
<p>Gender: <%= gender %></p>
<p>Hobby: <%= Arrays.toString(hobbies) %></p>
<p>Country: <%= country %></p>
<a href="updateForm.jsp?username=<%= username %>">Modify username</a>
</body>
</html>
<% } %>
```
3. updateForm.jsp 页面:
```html
<%
String username = request.getParameter("username");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Update Username</title>
</head>
<body>
<h1>Update Username</h1>
<form action="update.jsp" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" value="<%= username %>" required><br><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
```
4. update.jsp 页面:
```html
<%
String username = request.getParameter("username");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Update Success</title>
</head>
<body>
<h1>Update Success</h1>
<p>New username: <%= username %></p>
</body>
</html>
```
希望这个示例能够帮到你!
阅读全文