Bkjia.com documentI want to learn an example code Tutorial: how to display the xml Code returned by AJAX on a webpage, which consists of three parts, with comments added to the Code.
1. PostingXMLExample. java
Reference content is as follows:
PostingXMLExample. java
Package javabean;
Import java. io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Import javax. xml. parsers. DocumentBuilderFactory;
Import javax. xml. parsers. ParserConfigurationExcepTion;
Import org. w3c. dom. Document;
Import org. w3c. dom. NodeList;
Import org. xml. sax. SAXException;
Public class PostingXMLExample extends HttpServlet
{
Protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String xml = readXMLFromRequestBody (request );
Response. setContentType ("text/xml ");
PrintWriter out = response. getWriter ();
Out. println ("Hope said the result is: <Br>" + xml );
Out. close ();
}
Private String readXMLFromRequestBody (HttpServletRequest request)
{
StringBuffer xml = new StringBuffer ();
String line = null;
Try
{
BufferedReader reader = request. getReader ();
While (line = reader. readLine ())! = Null)
{
Xml. append (line );
}
}
Catch (Exception e)
{
System. out. println (e. toString ());
}
Return xml. toString ();
}
} |
- 2 pages in total:
- Previous Page
- 1
- 2
- Next Page