Java Reference
In-Depth Information
/**
* DoPost
* Pass post requests through to performTask
*/
public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
performTask(request, response);
}
This example is initiated from an input form, which calls doPost instead of
doGet as in our previous example. We simply pass the response and result
through to the performTask method.
/**********************************************************
* Process incoming requests for information
*
* @param request encapsulates the request to the servlet
* @param response encapsulates the response from the servlet
*/
public void performTask(
HttpServletRequest request,
HttpServletResponse response) {
try {
String board=request.getParameter("board");
CompoundJSPCommand postList = new CompoundJSPCommand();
postList.setBoard(board);
postList.initialize();
postList.execute();
Here, we parse the single input parameter provided by the form, and follow
our design pattern by issuing set s, initialize , execute , and get s (in our
controller and our JSP output page):
request.setAttribute("CompoundJSPCommand", postList);
ServletContext servletContext = getServletContext ();
RequestDispatcher dispatcher =
servletContext.getRequestDispatcher("/JSP/CompoundJSPResults.jsp");
dispatcher.forward(request, response);
} catch (Throwable theException) {
theException.printStackTrace();
}
}
/**
* DoGet
* Pass get requests through to performTask
*/
Search WWH ::




Custom Search