|
Building response XML message in server A Java Servlet is used to check the request from the client as in the first example. But this servlet is used in the POST method instead of the GET method.
The doPost() method of the servlet is to examine request in POST HTTP method from client,it looks like:
public void doPost(HttpServletRequest oRequest,HttpServletResponse oResponse) throws IOException,ServerException { // Get category name passed by client String strCategory = oRequest.getParameter("category")
// Get output writer PrintWriter oWriter = oResponse.getWriter();
// Set response in XML format oResponse.setContentType("text/xml"); oResponse.setHeader("Cache-Control","no-cache");
// Out XML message to client oWriter.print(getXMLResponseMessage(strCategory)); }
This code shows that when each POST request is caught,the servlet parses to get value of the category passed by the client and will look up for the list of books based on the given category,then respond it.
With XML message,we notice in:
·Set response message as XML format instead of TEXT as in the first example ·Build response XML message
The getXMLResponseMessage(strCategory) method is to build XML message containing a suggestion and a list of related books. It returns the message with a structure as below. In there,the suggestion node contains suggested categories and the books node contains a list of books it has.
<book_response> <suggestion></suggestion> <books> <book></book> <book></book> <book></book> </books>
</book_response>
|