/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.xml.resolve.action;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import com.oreilly.servlet.MultipartRequest;
/**
* MyEclipse Struts
* Creation date: 08-28-2009
*
* XDoclet definition:
* @struts.action scope="request"
*/
public class test extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
MultipartRequest mu = new MultipartRequest(request, System
.getProperty("user.dir"), 100000000, "gb2312");
File f = mu.getFile("file");//"file"为jsp界面中对应的File组件的名称
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.parse(f);
NodeList n=d.getElementsByTagName("Policy");
Node n1=n.item(0);
NodeList n2=n1.getChildNodes();//n2包含回车,因为DOM解析时会把回车当做一个节点
for(int i=0;i<n2.getLength();i++){
Node n3=n2.item(i);
if(n3.hasChildNodes()){
System.out.println(n3.getNodeName()+"="+n3.getTextContent());
}
}
} catch (Exception e) {
System.out.print("error");
return mapping.findForward("index");
}
return mapping.findForward("ok");
}
}