JSP Hosting

HostingServicesSupportOrderAbout UsSoftwareHome

Even experts read the manuals. Our tech support staff has most of the books that are out on a wide variety of web topics. Here are some of their top picks. We think you'll find them useful and informative as well.

Accepting GET method input

To do anything interesting with servlets, you need to accept input from the browser. This can be done by using the getParameter() method of the HttpServletRequest class. The following bold code demonstrates how we can accept a "name" variable with the doGet method of our our MyServlet class:

import javax.servlet.*;
import javax.servlet.http.*;

// MyServlet.java

public class MyServlet extends HttpServlet
 public void doGet ( HttpServletRequest req, HttpServletResponse res ) 
 throws ServletException, IOException { 
  String name = req.getParameter("name");
  res.setContentType( "text/html"); 
  PrintWriter out = res.getWriter(); 
  out.println( "<html><body>" );          
  out.println( "Hello there, " + name); 

Load this servlet using a query string appended to the URL such as the following to see how the servlet makes use of the GET method input.


<- Previous | Next ->

Note: MMA technical support staff cannot provide troubleshooting of problems with third-party CGI scripts including but not limited to: Perl scripts, C/C++ binaries, PHP or web/database integration unless these services are specifically contracted. For these services, please see our Quote Request Form.

Copyright © 1995-2012
Motivational Marketing Associates, LLC
All Rights Reserved.