日期:2014-05-20 浏览次数:20898 次
Message m = new Message(); LookMessage lm = new LookMessage(); List list = new ArrayList(); try { list = lm.getMessage(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } out.println("<title>查看留言</title>"); out.println("<table align=center border=1"); out.println("<tr><td colspan=3><font color=red>已发表留言有</font></td></tr>"); out.println("<tr><td><font color=red>姓名</font></td></tr><td><font color=red>内容</font></td><td><font color=red>时间</font></td>"); for(int i=0;i<list.size();i++){ m = (Message) list.get(i); out.println("<tr><td>"+m.getName()+"</td></tr>"); out.println("<tr><td>"+m.getContents()+"</td></tr>"); out.println("<tr><td>"+m.getDate()+"</td></tr>"); } out.println("</table>");
public List getMessage() { // TODO Auto-generated method stub List list = new ArrayList(); StringBuffer sb = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(new File("mbs.xml")); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } Element root = doc.getRootElement(); List nodes = root.elements("value"); for(Iterator it = nodes.iterator();it.hasNext();){//循环有几个"value"节点 Element elm = (Element) it.next(); Message m = new Message(); for(Iterator itr = elm.elementIterator();itr.hasNext();){//循环“value”下面的节点 Element e1 = (Element) itr.next(); m.setName(e1.getText()); Element e2 = (Element) itr.next(); m.setContents(e2.getText()); Element e3 = (Element) itr.next(); m.setDate(e3.getText()); list.add(m); // System.out.println("根节点"+e.getText()); } } return list; }