用mvc写一个注册程序代码
User.java
package com.mjrg.domain;
import java.util.Date;
public class User {
private String id;
private String name;
private String password;
private String email;
private Date birthday;
private String nickname;
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 String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
}
XmlUtils.java
package com.mjrg.utils;
import java.io.File;
import java.io.FileOutputStream;
import
java.io.IOException;
import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
public class XmlUtils {
private static String filepath;
static{
//得到"users.xml"的路劲
filepath=XmlUtils.class.getClassLoader().getResource("users.xml").getPath();
}
public static Document getDocument() throws Exception{
SAXReader reader=new SAXReader();
Document document=reader.read(new File(filepath));
return document;
}
public static void write2Xml(Document document) throws
IOException{
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
XMLWriter writer=new XMLWriter(new FileOutputStream(filepath),format);
writer.write(document);
writer.close();
}
}
UserDaoImpl.java
package com.mjrg.dao.impl;
import java.text.SimpleDateFormat;
import org.dom4j.Document;
import org.dom4j.Element;
import com.mjrg.domain.User;
import com.mjrg.utils.XmlUtils;
public class UserDaoImpl {
public void add(User user){
try {
Document document=XmlUtils.getDocument();
Element root=document.getRootElement();
Element user_tag=root.addElement("user");
user_tag.setAttributeValue("id", user.g