5 Replies Latest reply: Jan 18, 2012 10:12 PM by Leena Jain123 RSS

    Submit the form XML to a URL over HTTP

    amateur85 Community Member

      Hi,

       

      I need tips on how to use Submit to URL functionality on the form .

       

      I want the form xml to be submitted to a URL . I understand that there will be a button on the form on which i can specilfy the URL .

       

      But how on the other end i can retrieve that xml and use it ? Can anybody help me with the sample code .

       

      Thanks

       

      Message was edited by: ashish gupta. to make the title more descriptive.

        • 1. Re: Submit to URL
          Steve L Walker techies

          What kind of technology are you running on the server?

           

          If you are Microsoft-centric with an IIS HTTP server you probably should consider an ASP server-side. If you are Java-centric with Apache, Tomcat, JBoss, for example, you should probably consider a JSP (Java server page) or a Java servlet server-side. Or maybe you are running Apache and PHP.

           

          Steve

          • 2. Re: Submit to URL
            amateur85 Community Member

            I will be using Tomcat with servlet . I need to know what exactly i need to code on the servlet side to get the input xml from the form and use it .

            Will the xml be in the adode document format ?

             

            Thanks

            • 3. Re: Submit to URL
              Steve L Walker techies

              If you are unfamiliar with Java this may be a challenge. The servlet below uses the Java IO package to convert the servlet input stream to a string buffer to a string. The DOM4J XML parser is then used to convert the string to an XML document. The servlet writes the XML document to c:\\pdf.xml and sends an HTML response back to the browser (and Preview in Designer which is actually an HTML container) indicating "The XML data was successfully written to c://pdf.xml." A sample pdf.xml is attached.

               

              NOTE: You cannot submit data from the attached PDF in Reader or Acrobat stand-alone. The PDF has to be opened in a browser. Additional scripting is required to submit data from a PDF in Reader or Acrobat stand-alone.

               

              From LiveCycle Designer Preview I can fill the form with data and hit the Submit button resulting a call to the servlet.

               

              Untitled.png

               

              The servlet responds with HTML which is written in the browser container.

               

              Untitled1.png

              Untitled2.png

               

              DOM4J is the simplest of the XML parsers for the task. You will need to use a Java IDE such as Eclipse to configure a project to use the Java APIs, the servlet APIs and DOM4J. Alternatively you can use a good old fashioned text editor and a batch file to compile the Java class.

               

               

              import java.io.IOException;

              import java.io.InputStream;

              import java.io.FileOutputStream;

              import java.io.PrintWriter;

               

              import javax.servlet.ServletException;

              import javax.servlet.http.HttpServlet;

              import javax.servlet.http.HttpServletRequest;

              import javax.servlet.http.HttpServletResponse;

               

              import org.dom4j.Document;

              import org.dom4j.DocumentHelper;

              import org.dom4j.DocumentException;

              import org.dom4j.io.OutputFormat;

              import org.dom4j.io.XMLWriter;

               

              public class ReadAndWriteXml extends HttpServlet {

               

               

              private static final long serialVersionUID = 1L;

               

              protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                   doPost(req,resp);

              }

               

              protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                   try {

                        InputStream inputStream = req.getInputStream();

                        StringBuffer stringBuffer = new StringBuffer();

                        byte[] bytes = new byte[4096];

                        for (int n; (n = inputStream.read(bytes)) != -1;) {

                             stringBuffer.append(new String(bytes, 0, n));

                        }

                        String xmlStr = new String(stringBuffer.toString());

                        String filePath = "C://pdf.xml";

                        FileOutputStream fileOutputStream = new FileOutputStream(filePath);

                        OutputFormat format = OutputFormat.createPrettyPrint();

                        XMLWriter xmlWriter = new XMLWriter(fileOutputStream, format);

                        xmlWriter.write(convertString2Document(xmlStr));

                        xmlWriter.flush();

               

                        resp.setContentType("text/html");

                        PrintWriter out = resp.getWriter();

                        out.println("<html><body><center>");

                        out.println("<p>The XML data was successfully written to c://pdf.xml.</p>");

                        out.println("</center></body></html>");

                   }

                   catch (Exception e) {

                        System.out.println("The following exception occurred: "+ e.getMessage());

                   }

              }

               

              public Document convertString2Document(String xml) throws DocumentException {

                   Document document = null;

                   try {

                        document = DocumentHelper.parseText(xml);

                   }

                   catch (DocumentException e) {

                        e.printStackTrace();

                   }

                   return document;

              }

               

              }

               

              Steve

              • 4. Re: Submit to URL
                amateur85 Community Member

                Thanks a lot Steve . I will use this code  .  Please help me with the javascript code also which i need to write on the submit button , because what i assumed that just giving the servlet URL on the button will solve the purpose . The xml data to be submitted is coming from a stand alone pdf .

                 

                Thanks

                • 5. Re: Submit to URL
                  Leena Jain123

                  HI ,

                  Can we send the entire PDF?How?I am using dot net at server side.

                   

                  Thanks ,

                  Leena