IBM Version 5 Universal Remote User Manual


 
Chapter 11. Light weight XML-based Enterprise Application 273
Modifying the doPost method
Now we need to modify the doPost method. All we need to do is invoke the
doQuery method with HttpServletRequest. We are reusing same form with
registration, we need to add another button to query. We define the button as
queryBtn, and check in the doPost method. If queryBtn is pressed, doPost
proceeds to doQuery and shows. Once the doQuery succeeds, go showpage to
show results. If it fail, go back to the input form which will be reproduced by doGet
method. The doGet method reuses the XML Document that is currently
instantiated in the servlet instance, and the membership field has been replaced
with -
1, which is the Membership already existed message.
Example 11-9 CustomerXSLServlet doPost method for query
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if( request.getParameter("queryBtn") != null ){
showPage(resultStylesheet, response, doQuery(request));
}else{
if( doRegister(request) == true){
showPage(resultStylesheet, response, doQuery(request));
}else{
doGet(request, response);
}
} }
Modifying the showPage method
The showPage method takes an output document as the third parameter. The
parameter is org.w3c.dom.Document type, so to run under Application Developer
4.0.3, you need to use following statement:
transformer.transform(new StreamSource(
new StringReader(resultdata)), new StreamResult(writer));
Example 11-10 showPage method
private void showPage(Templates stylesheet, HttpServletResponse response,
org.w3c.dom.Document doc)
throws IOException
{
try
{
Transformer transformer = stylesheet.newTransformer();
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));