// Fig. 26.15: WelcomeServlet3.java
// Processing post requests containing data.
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class WelcomeServlet3 extends HttpServlet
{
// process "post" request from client
protected void doPost( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
String firstName = request.getParameter( "firstname" );
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
// send XHTML page to client
// start XHTML document
out.println( "" );
out.printf( "%s%s%s", "\n" );
out.println( "" );
// head section of document
out.println( "
" );
out.println(
"Processing post requests with data" );
out.println( "" );
// body section of document
out.println( "" );
out.println( "Hello " + firstName + ",
" );
out.println( "Welcome to Servlets!
" );
out.println( "" );
// end XHTML document
out.println( "" );
out.close(); // close stream to complete the page
} // end method doPost
} // end class WelcomeServlet3
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/