加班提问(郁闷中):如何将一个FORM中提交的3个表格分别保存在3个XML文件中,在线等待。。。 在一个form里面有三个table,当我点击按钮提交这个form的时候,如何将这三个table分别保存在三个XML文件中。请大家给个思路,如果有类似的代码提供,更是不胜感激!祝各位五一玩的开心 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我说下思路:HTML结构:<form action=".."> <table> ... </table> <table> ... </table> <table> ... </table></form>submit后,存储3个Table的数据到3个数据结构中(如Vector等)Table中的数据可以通过request.getParameter()来得到吧。有了数据就开始写XML文件,写一个写入到XML的方法:public void writeToXML(String filename,Vector data);实现自己去写吧,我只给你提供这个思路,能看懂么? public void writeToXML(String filename,Vector data)的基本实现:import java.io.*;import java.util.*;import javax.xml.parsers.*;import org.w3c.dom.*;import org.apache.crimson.tree.XmlDocument;public static void writeXMLFile(String file,Vector vector) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = dbf.newDocumentBuilder(); } catch(ParserConfigurationException pce) { pce.printStackTrace(); System.exit(1); } Document doc = null; doc = db.newDocument(); //write ROOT Element root = doc.createElement("root"); doc.appendChild(root); for(int i=0;i<vector.size();i++) { Element e = doc.createElement("data"); getData()得到数据........ e.setAttribute(name,value); e.setAttribute(name,value); ....... root.appendChild(e); } FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos); ((XmlDocument)doc).write(osw); System.out.println("Write finished."); osw.close(); }注:把每个Table中的数据封装起来,方便getData()取数据。 bat中执行java 【疑惑】JAVA异常处理 初学 JAVA 3D 环境配置不出来了 求高人指点。 jComboBox事件问题 java用什么组件可以显示一个网页形式文件 如何把自己的个人计算机做成ftp服务器,使得其他远程个人计算机将数据发送到我的机器上。 怎样在jTextArea上实现undo 和 redo 请问编译java程序出现的一个问题 菜鸟级问题一个,愿者请进。 window开发ssh项目本地没问题,部署到linux服务器报错,贴出日志麻烦大家帮忙看看 图象文件,文本文件编译打包以后,怎么就不可用了?? java -Djava.security.policy求助
HTML结构:
<form action="..">
<table> ... </table>
<table> ... </table>
<table> ... </table>
</form>submit后,存储3个Table的数据到3个数据结构中(如Vector等)
Table中的数据可以通过request.getParameter()来得到吧。
有了数据就开始写XML文件,写一个写入到XML的方法:
public void writeToXML(String filename,Vector data);实现自己去写吧,我只给你提供这个思路,能看懂么?
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.crimson.tree.XmlDocument;
public static void writeXMLFile(String file,Vector vector) throws Exception
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try
{
db = dbf.newDocumentBuilder();
}
catch(ParserConfigurationException pce)
{
pce.printStackTrace();
System.exit(1);
}
Document doc = null;
doc = db.newDocument();
//write ROOT
Element root = doc.createElement("root");
doc.appendChild(root);
for(int i=0;i<vector.size();i++)
{
Element e = doc.createElement("data");
getData()得到数据........
e.setAttribute(name,value);
e.setAttribute(name,value);
.......
root.appendChild(e);
}
FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos);
((XmlDocument)doc).write(osw);
System.out.println("Write finished.");
osw.close();
}注:把每个Table中的数据封装起来,方便getData()取数据。