OrderEntryServlet.java code excerpt.

Power Java
Techniques for Optimizing Web Site Development and Runtime Characteristics

Christopher A. Fregly
Listing 4. OrderEntryServlet.java code excerpt.


public
void doPost( HttpServletRequest request, HttpServletResponse response ){

//Retrieve NavigationFacility instance (implemented as a Singleton)
NavigationFacility nav = NavigationFacility.getInstance()

String navAction = request.getParameter( "navAction" );
String currentSceneName = request.getParameter( "currentSceneName" );

if ( ( navAction != null ) && ( currentSceneName != null ) ){
  if ( navAction.equals( "SubmitOrderAction" ) ){
             // [Insert order validation and submit here...]
             //Assume order is valid and submitted to back end
             //successfully...
             //Set the next scene based on the selected Take: current
             //scene, the action taken, and the result
             TransitionSelector selector = new TransitionSelector(
             currentSceneName, navAction, "Success" );
             nav.selectTransition( selector );
  }
  else
  if ( navAction.equals( "CancelOrderAction" ) ){
             //[Insert cancel order here...]
             //Assume cancel order is successful...
             TransitionSelector selector = new TransitionSelector(
             currentSceneName, navAction, "Success" );
             nav.selectTransition( selector );
  }

  //Get the next scene
  Scene scene = nav.getNextScene();
  //Redirect to the next scene
  response.sendRedirect( scene.getURL() );
  }
}

About the Author

Christopher A. Fregly is Senior Cunsultant for BEA Systems Inc. in Chicago. He can be contacted at chris@fregly.