大致思路:用Servlet,JSP写一个学生信息的增删改查。JSP的<body>里面写form表单,然后将信息提交到servlet,最后将数据保存到数据库中。
大致步骤:
1. 创建学生对象----->以学生对象作为信息的载体Java类bin(也称实体bin)
创建学生类----->定义学号,姓名,性别,年龄,分数等属性,----->generate getters and setters方法
public class Student { private String stuNo; private String stuName; private int gender; private int score; private int age; /** * @return the stuNo */ public String getStuNo() { return stuNo; } /** * @param stuNo the stuNo to set */ public void setStuNo(String stuNo) { this.stuNo = stuNo; } /** * @return the stuName */ public String getStuName() { return stuName; } /** * @param stuName the stuName to set */ public void setStuName(String stuName) { this.stuName = stuName; } /** * @return the gender */ public int getGender() { return gender; } /** * @param gender the gender to set */ public void setGender(int gender) { this.gender = gender; } /** * @return the score */ public int getScore() { return score; } /** * @param score the score to set */ public void setScore(int score) { this.score = score; } /** * @return the age */ public int getAge() { return age; } /** * @param age the age to set */ public void setAge(int age) { this.age = age; } }
2.在JSP中写form表单
(由于gender不能输入 type=“radio”) ----->提交按钮
<div align="center"> <h3>学生信息维护</h3> <hr> <form action="<%=ctxPath %>/student/add" method="post"> <table> <tr> <td>学生编号</td> <td><input type="text" name="stuNo"></td> </tr> <tr> <td>学生姓名</td> <td><input type="text" name="stuName"></td> </tr> <tr> <td>性别</td> <td><la