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.
Solved! Go to Solution.
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.
The servlet responds with HTML which is written in the browser container.
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
The servlet responds with HTML which is written in the browser container.
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
HI ,
Can we send the entire PDF?How?I am using dot net at server side.
Thanks ,
Leena
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies