package com.zhangjun.test; import java.io.FileOutputStream; import java.io.IOException; import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.Date; import javax.enterprise.deploy.model.DDBean; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.XMLSerializer; import org.w3c.dom.Document; import org.w3c.dom.Element; import com.sun.org.apache.xerces.internal.dom.DocumentImpl; import com.zhangjun.xml.AddItem; @SuppressWarnings("serial") public class TableServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("GBK"); response.setContentType("text/html;charset=GBK"); HttpSession session = request.getSession(); Document dom = null; int iAllotedCount = 0; AddItem ad = new AddItem(); dom = new DocumentImpl(); Element root = dom.createElement("documents"); dom.appendChild(root); int j = 1; for(int i=0;i<100;i++) { iAllotedCount++; Element row = dom.createElement("row"); root.appendChild(row); row.setAttribute("count", "" + j++); int jj = 1; ad.addItem(dom, row,"选择","<input id=\"ch\" name=\"ch\" type=\"checkbox\" value=\"\" onclick=\"choice();\">","N","HTML",jj++); ad.addItem(dom, row, "序号", ""+iAllotedCount, "N", "", jj++); ad.addItem(dom, row, "姓名", "张三", "N", "", jj++); ad.addItem(dom, row, "性别", "男", "N", "", jj++); ad.addItem(dom, row, "年龄", "24", "N", "", jj++); ad.addItem(dom, row, "身高", "177", "N", "", jj++); ad.addItem(dom, row, "出生日期", "1988-01-16", "N", "", jj++); ad.addItem(dom, row, "出生地", "山东", "N", "", jj++); ad.addItem(dom, row,"操作","<a href=\"ditxiangmu.htm\">编辑</a>|<a href=\"listxiangmumingxi.htm\">查看</a>","N","HTML",jj++); } if (iAllotedCount == 0) { dom = null; } // logInfo("D:\\zhangjun.txt",dom2String(dom)); // logInfo("changxiangLog.txt"," handle changxiang data at " + new java.util.Date() +"\n\r",true); logInfo("changxiangDataLog.txt"," handle changxiang data at " + new java.util.Date() +"\n\r" +"="+ dom2String(dom) +"\n\r",true); session.setAttribute("domList",dom); response.sendRedirect(request.getContextPath()+"/domList.jsp"); } public static void logInfo(String filename,String info,boolean append) //按照GBK编码保存数据到文件,如果文件存在,追加数据到文件中。 { try { FileOutputStream out=new FileOutputStream(filename,append); byte bt_prompt[]=info.getBytes("GBK"); out.write(bt_prompt); out.close(); } catch (Exception e) { System.out.println("com.taikang.utils.FileFunc.logInfo:"+e); } } public static void logInfo(String filename,String info) //按照GBK编码保存数据到文件。 { try { FileOutputStream out=new FileOutputStream(filename); byte bt_prompt[]=info.getBytes("GBK"); out.write(bt_prompt); out.close(); } catch (Exception e) { System.out.println("com.taikang.utils.FileFunc.logInfo:"+e); } } /** * 将document对象,转换成字符串数据 * @param dom * @return */ public static String dom2String(Document dom) // 将document对象,转换成字符串数据。 { String aa = new String(); try { StringWriter ss = new StringWriter(); OutputFormat format = new OutputFormat(dom); // Serialize DOM format.setEncoding("GB2312"); XMLSerializer serial = new XMLSerializer(ss, format); serial.asDOMSerializer(); // As a DOM Serializer serial.serialize(dom.getDocumentElement()); aa = ss.toString(); ss.flush(); ss.close(); } catch (Exception e) { // return false; } return aa; } }
最近下载更多
最近浏览更多
cz8857216 LV4
3月8日
fesfefe LV13
1月26日
uni-code_0123 LV1
2023年11月11日
EFWAGGFAWGR
2023年10月19日
暂无贡献等级
微信网友_6467077197238272 LV1
2023年5月8日
lironggang LV38
2023年3月28日
zjc010726
2023年3月15日
暂无贡献等级
qwqw900619 LV4
2022年7月16日
nbzhou2013 LV14
2022年4月4日
一直都会顺利的小吴 LV5
2022年2月16日