Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
68
Chapter 3 Handling the Client Request: Form Data
Figures 3 1 and 3 2 show the result of the HTML front end and the serv 
let, respectively. 
Listing 3.1 ThreeParams.java 
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ThreeParams extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Reading Three Request Parameters";
    out.println(ServletUtilities.headWithTitle(title) +
                "\n" +
                "

" + title + "

\n" +
                "
                "  
  • param1: "
  •                 + request.getParameter("param1") + "\n" +
                    "  
  • param2: "
  •                 + request.getParameter("param2") + "\n" +
                    "  
  • param3: "
  •                 + request.getParameter("param3") + "\n" +
                    "\n" +
                    "");
      }
    }
    Although you are required to specify response settings (see Chapters 6 and
    7) before beginning to generate the content, there is no requirement that you
    read the request parameters at any particular time. 
    If you're accustomed to the traditional CGI approach where you read
    POST
     data through the standard input, you should note that you can do the
    same thing with servlets by calling 
    getReader
     or 
    getInputStream
     on the
    HttpServletRequest
     and then using that stream to obtain the raw input.
    This is a bad idea for regular parameters since the input is neither parsed
    (separated into entries specific to each parameter) nor URL decoded
    (translated so that plus signs become spaces and %XX gets replaced by the
    Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
    Servlet and JSP training courses by book's author: courses.coreservlets.com.
    
    
    
    
    
    
    footer
    
    
    
    
    

     

     

     

     

     Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

    jsp web hosting

     

    Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

    Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved