Using the two functions I wrote in (ii) (put in package src), I implemented the Web page operation this time.
Index.html:
<%@ page language= "java" pageencoding= "GB2312"%>
<body>
<p></p>
<p></p>
<p></p>
<table width= "60%" border= "1" align= "Center" >
<tr>
<td>
<p align= "left" ><font size= "4" color= "#003399" > Management test Program </font></p>
<form name= "Readform" Method=post action= "load.jsp" >
<p align= "left" ><font color= "#FF0000" > Read XML file: </font></p>
<p align= "Left" > <font color= "#FF0000" >
<input type= "text" name= "MyPath" size= "" value= "C:eclipseworkspacemyxmlxmldata1.xml" >
</font></p>
<p align= "Left" >
<a href= "http://j5c.cnblogs.com/index.php#" Onclick=submit () > Read </a>
</p>
<p align= "left" ></p>
</form>
<form name= "WriteForm" Method=post action= "create.jsp" >
<p align= "left" ><font color= "#FF0000" > Write to XML file:</font> </p>
<p align= "Left" > Please fill in the path:
<input type= "text" name= "MyPath" width= "50" size= "
Value= "C:eclipseworkspacemyxmlxmldata11.xml" >
</p>
<p align= "Left" > Please fill in the title:
<input type= "text" name= "MyTitle" width= "M" size= ">"
</p>
<p align= "Left" > Please fill in the content:
<textarea name= "mycontent" cols= "></textarea>"
</p>
<p align= "Left" >
<a href= "http://j5c.cnblogs.com/index.php#" Onclick=submit () > Write </a>
</p>
</form>
</td>
</tr>
</table>
</body>
Page create.jsp to write:
<%@ 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.*"%>
<body>
<%
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.");
}
%>
</body>
Read the XML page 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.*" %>
<body>
<%
Vector A=new Vector();
String mypath=(String)request.getParameter("mypath");
out.println(mypath);%>
<p>
<%
readxml my = new readxml();
A = my.toRead(mypath);
for (int i = 0; i < A.size(); i++) {
out.println(A.elementAt(i));
%>
<p>
<%
}
%>
</body>
There is also a flaw in the write program, which simply creates XML format and content, rather than overwriting existing files.