␡
- A Refresher
- The Servlet Class: TransformData
- Helper Class: URLDecoder
- Main Transformation Class: FormDataToXML
- Conclusion
Like this article? We recommend
The Servlet Class: TransformData
The form submitted from the user's Web browser to the Web server is processed by the Java servlet TransformData.class. The class is implemented as follows:
/** * TransformData servlet * * @Author Jasmit Singh Kochhar * * @Date Created 08/2001 * * @Purpose This is the main servlet for transforming * HTML data into XML strings * */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class TransformData extends HttpServlet { public void init (ServletConfig config) throws ServletException { super.init(config); } /* init */ /** * Method: doPost * * @Purpose This method receives the request information. * It then parses the request to determine the values of * various key attributes and builds an XML Query with the * remaining attributes by calling the FormDatatoXML class. */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String QueryString = new String(); // Get the Query String QueryString = request.getQueryString(); String xmlString; // Transform into an XML document FormDataToXML h = new FormDataToXML(); xmlString=h.toXML(htmlString); // Send the response to the user browser as an XML string response.setContentType("text/xml"); PrintWriter out = new PrintWriter(response.getOutputStream()); out.println(xmlString); out.flush(); return; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doPost(request, response); } } /* End of TransformData */