标签:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ziptool</title> <script> function fuzhi() { alert(document.getElementById(‘path‘).value); } function browseFolder(path) { try { var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息 var Shell = new ActiveXObject("Shell.Application"); var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //起始目录为:我的电脑 //var Folder = Shell.BrowseForFolder(0, Message, 0); //起始目录为:桌面 if (Folder != null) { Folder = Folder.items(); // 返回 FolderItems 对象 Folder = Folder.item(); // 返回 Folderitem 对象 Folder = Folder.Path; // 返回路径 if (Folder.charAt(Folder.length - 1) != "\\") { Folder = Folder + "\\"; } Folder= Folder.replace(/\\/g,"/"); document.getElementById(path).value = Folder; return Folder; } } catch (e) { alert(e.message); } } </script> </head> <body> <div id="header"><h1>欢迎使用ziptool</h1></div> <div id="menu"><b>筛选要求</b></div> <div id="workspace"> <table> <tr> <td>请选择需要压缩的文件的位置</td> <td><input id="path" type="text" name="path" size="30" onchange="fuzhi()"></td> <td><input type=button value="选择" onclick="browseFolder(‘path‘)" ></td> </tr> <tr> <td>请选择压缩文件的存放位置</td> <td><input id="path1" type="text" name="path" size="30" onchange="fuzhi2()"></td> <td><input type=button value="选择" onclick="browseFolder(‘path1‘)"></td> </tr> </table> </div> </body> </html>
前台页面
package sample; import java.io.IOException; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; public class Unzip { /** * @param args * @throws IOException * @throws JDOMException */ //文件zip打包 public static void main(String[] args) throws JDOMException, IOException { // TODO Auto-generated method stub SAXBuilder sb=new SAXBuilder(); Document doc=sb.build("unzip.xml"); Element root =doc.getRootElement(); List<Element> lst=root.getChildren("property"); for(Element el :lst) { if(el.getAttributeValue("name").equals("jieyawenjian")) el.setAttribute("value", "d://xutianhao_caozuo/sunzekun.zip"); if(el.getAttributeValue("name").equals("jieyamulu")) el.setAttribute("value","e://XTH_caozuo/ant+jdom/new"); }//找寻属性名name为目标文件的子元素 修改value属性 SaveXml.saveXML(doc); Runtime.getRuntime().exec("cmd /k ant -f unzip.xml"); //通过在cmd执行ant命令执行build.xml System.out.println("chenggong"); } }
解压文件
package sample; import java.io.FileWriter; import java.io.IOException; import org.jdom.Document; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; public class SaveXml { public static void saveXML(Document doc) throws IOException{ XMLOutputter xmlopt=new XMLOutputter(); //创建xml文件输出流 FileWriter writer= new FileWriter("zip.xml"); //构建输出对象到zip.xml Format fm = Format.getPrettyFormat(); xmlopt.setFormat(fm); //指定文档格式 xmlopt.output(doc, writer); //将doc写入到指定的文件夹中 writer.close(); } }
保存xml
package sample; import java.io.IOException; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; public class Sample2 { /** * @param args * @throws IOException * @throws JDOMException */ //文件zip打包 public static void dabao(String mulu,String mubiao) throws IOException, JDOMException{ SAXBuilder sb=new SAXBuilder(); Document doc=sb.build("zip.xml"); Element root =doc.getRootElement(); List<Element> lst=root.getChildren("property"); for(Element el :lst) { if(el.getAttributeValue("name").equals("mubiaowenjian")) el.setAttribute("value", mubiao); if(el.getAttributeValue("name").equals("mulu")) el.setAttribute("value", mulu); }//找寻属性名name为目标文件的子元素 修改value属性 SaveXml.saveXML(doc); Runtime.getRuntime().exec("cmd /k ant -f zip.xml"); //通过在cmd执行ant命令执行build.xml System.out.println("chenggong"); } public static void main(String[] args) throws JDOMException, IOException { // TODO Auto-generated method stub dabao("E:/xutianhao/linshi","E:/xutianhao/linshi"); } }
后台处理
标签:
原文地址:http://www.cnblogs.com/tianhao/p/4284724.html