利用(二)中我写的两个函数(放在package src中),这次实现web页面的操作。
index.html:
<%@ page language="java" pageEncoding="GB2312"%>
写入的页面create.jsp:
<%@ page language="java" pageEncoding="GB2312"%>
<%@ page import="src.*" %>
<%@ page import="org.w3c.dom.*"%>
<%@ page import="javax.xml.parsers.*"%>
<%@ page import="javax.xml.transform.*"%>
<%@ page import="javax.xml.transform.dom.DOMSource"%>
<%@ page import="javax.xml.transform.stream.StreamResult"%>
<%@ page import="java.io.*"%>
<%
String mypath=(String)request.getParameter("mypath");
String mytitle=(String)request.getParameter("mytitle");
String mycontent=(String)request.getParameter("mycontent");
mypath=new String(mypath.getBytes("ISO-8859-1"),"GB2312");
mytitle=new String(mytitle.getBytes("ISO-8859-1"),"GB2312");
mycontent=new String(mycontent.getBytes("ISO-8859-1"),"GB2312");
try{
writexml myxml=new writexml(mypath);
myxml.toWrite(mytitle,mycontent);
myxml.toSave();
out.print("Your writing is successful.");
}
catch(ParserConfigurationException exp){
exp.printStackTrace();
out.print("Your writing is failed.");
}
%>
读取xml的页面load.jsp:
<%@ page language="java" pageEncoding="GB2312"%>
<%@ page import="src.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.Vector" %>
<%@ page import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%
Vector A=new Vector();
String mypath=(String)request.getParameter("mypath");
out.println(mypath);%>
<%
readxml my = new readxml();
A = my.toRead(mypath);
for (int i = 0; i < A.size(); i++) {
out.println(A.elementAt(i));
%>
<%
}
%>
这个写程序还有一个缺陷,它只是创建xml格式和内容,而不是改写已有文件。
【责编:admin】
--------------------next---------------------