|
|||||
|
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);
out.close();
}
}
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. http://www.yourdomain.com/servlet/MyServlet?name=Michael 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-2000
Motivational Marketing Associates, LLC
All Rights Reserved.