编写-个StudentBean类,在其中定义的学生属性有学号、姓名、性别、籍 贯、年龄专业,各属性的命名按照Java命名规则自行完成。 (2)设计一个studertInpujsp页面,通过表单输入S
时间: 2024-11-15 21:20:36 浏览: 12
首先,我将为你编写一个名为`StudentBean`的Java类,这个类代表了一个学生实体,包含了常见的学生信息属性:
```java
public class StudentBean {
// 学生属性
private String studentID; // 学号
private String name; // 姓名
private String gender; // 性别
private String hometown; // 籍贯
private int age; // 年龄
private String major; // 专业
// 构造函数
public StudentBean(String studentID, String name, String gender, String hometown, int age, String major) {
this.studentID = studentID;
this.name = name;
this.gender = gender;
this.hometown = hometown;
this.age = age;
this.major = major;
}
// getter和setter方法
public String getStudentID() { return studentID; }
public void setStudentID(String studentID) { this.studentID = studentID; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getGender() { return gender; }
public void setGender(String gender) { this.gender = gender; }
public String getHometown() { return hometown; }
public void setHometown(String hometown) { this.hometown = hometown; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getMajor() { return major; }
public void setMajor(String major) { this.major = major; }
}
```
接下来,我会创建一个名为`studentInput.jsp`的JSP页面,该页面用于接收用户输入并显示在StudentBean对象中:
```html
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>Student Input</title>
</head>
<body>
<form action="submitStudent" method="post">
<label for="studentID">学号:</label>
<input type="text" id="studentID" name="studentID"><br><br>
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br><br>
<label for="gender">性别:</label>
<select id="gender" name="gender">
<option value="male">男</option>
<option value="female">女</option>
</select><br><br>
<label for="hometown">籍贯:</label>
<input type="text" id="hometown" name="hometown"><br><br>
<label for="age">年龄:</label>
<input type="number" id="age" name="age"><br><br>
<label for="major">专业:</label>
<input type="text" id="major" name="major"><br><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
在这个JSP页面上,用户可以填写学生的各项信息,然后通过POST请求提交到指定的服务器端处理程序(例如`submitStudent`)。
阅读全文