我写了一个类,操作xml的,对xml进行取值和更改值,各个操作没有问题的,但是我在jsp页面中更改了值以后,再直接取出取出不到更改以后的值,请问高手怎么解决啊?以下是我的类:
package dmb.javamail;import java.io.FileInputStream;
import java.io.FileOutputStream;import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;public class InitEmail {
private String smtpServer;
private String smtpEmail;
private String smtpUser;
private String smtpPassword;
private SAXBuilder builder;
private Document doc;
public String getSmtpPassword() {
return smtpPassword;
}public void setSmtpPassword(String smtpPassword) {
this.smtpPassword = smtpPassword;
}public String getSmtpServer() {
return smtpServer;
}public void setSmtpServer(String smtpServer) {
this.smtpServer = smtpServer;
}public String getSmtpUser() {
return smtpUser;
}public void setSmtpUser(String smtpUser) {
this.smtpUser = smtpUser;
}
public InitEmail() {
builder= new SAXBuilder();try{
doc=builder.build(this.getClass().getResourceAsStream("initmail.xml"));Element ele=doc.getRootElement();
smtpServer = ele.getChild("smtp_server").getTextTrim();
smtpEmail = ele.getChild("smtp_email").getTextTrim();
smtpUser = ele.getChild("smtp_user").getTextTrim();
smtpPassword = ele.getChild("smtp_password").getTextTrim();
this.getClass().getResourceAsStream("initmail.xml").close();
}catch(Exception ex){
ex.printStackTrace();
}
}/**
 * @param args
 */public void updateMailServer(String server,String email,String user,String password){
try{
builder=new SAXBuilder();
//builder.build(this.getClass().getResourceAsStream("initmail.xml"));
doc=builder.build(this.getClass().getResourceAsStream("initmail.xml"));
Element ele=doc.getRootElement();
ele.getChild("smtp_server").setText(server);
ele.getChild("smtp_email").setText(email);
ele.getChild("smtp_user").setText(user);
ele.getChild("smtp_password").setText(password);
XMLOutputter xmlo = new XMLOutputter("  ", true, "UTF-8");
String path=this.getClass().getResource("").getPath();
System.out.println(path.substring(1,path.length()));
FileOutputStream output =  new FileOutputStream(path.substring(1,path.length())+"initmail.xml");
    xmlo.output(doc,output);
   // xmlo=null;  
output.flush();
output.close();
    
  
}catch(Exception ex){
ex.printStackTrace();
}
}public static void main(String args[]){
new InitEmail().updateMailServer("","","","");;
}public String getSmtpEmail() {
return smtpEmail;
}public void setSmtpEmail(String smtpEmail) {
this.smtpEmail = smtpEmail;}}还有我的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mailinfo>    <smtp_server>smtp.126.com</smtp_server><smtp_email>maxinlianggedm</smtp_email>    <smtp_user>maxinlianggenius</smtp_user>    <smtp_password>990714</smtp_password>
</mailinfo>