Example: how to display xml Code returned by AJAX on a webpage

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.