日期:2014-05-17 浏览次数:20696 次
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form action="/StuRecServlet" method="post"> 姓名:<input type="text" name="name"/><br/> 性别:<input type="radio" name="sex" value="true"/>男 <input type="radio" name="sex" value="false"/>女<br/> 年龄:<input type="text" name="age" /><br/> 班级:<input type="text" name="className" /><br/> <input type="submit" value="提交信息" /> </form> </body> </html>
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>StuRecServlet</servlet-name> <servlet-class>cn.itcast.servlet.student.StuRecServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>StuRecServlet</servlet-name> <url-pattern>/StuRecServlet</url-pattern> </servlet-mapping> <servlet> <servlet-name>StuManServlet</servlet-name> <servlet-class>cn.itcast.servlet.student.StuManServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>StuManServlet</servlet-name> <url-pattern>/StuManServlet</url-pattern> </servlet-mapping> <servlet> <servlet-name>StuDelServlet</servlet-name> <servlet-class>cn.itcast.servlet.student.StuDelServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>StuDelServlet</servlet-name> <url-pattern>/StuDelServlet</url-pattern> </servlet-mapping> </web-app>
package cn.itcast.servlet.domain; public class Student { private String id; private String name; private boolean sex; private String age; private String className; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public boolean isSex() { return sex; } public void setSex(boolean sex) { this.sex = sex; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } @Override public String toString() { return "Student [id=" + id + ", name=" + name + ", sex=" + sex + ", age=" + age + ", className=" + className + "]"; } } package cn.itcast.servlet.dao; import java.util.List; public interface IStudentDAO { List<Student> getAllStudents(); void addStudent(Student stu); void deleteStudent(String id); // void updateStudent(Student stu); } package cn.itcast.servlet.dao; import java.io.File; public class StudentDAOImpl implements IStudentDAO { private final static String XMLFile = "D:\\Java\\WorkSpace\\MyWebApps\\webdoc\\student.xml"; /** * 获取Document对象. * * @return */ public Document getDoc() { DocumentBuilder builder = null; Document doc = null; try { builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); d