Class 2 |
Intermediate Java 30-IT-397 |
|
Servlets
-
Servlets are Java programs that generate dynamic HTML.
-
When translated, JSPs become servlets.
-
Servlets retrieve information from a submitted web page via the GET or
POST methods.
-
These methods are assigned in the METHOD parameter of the HTML FORM tag.
-
GET sends the information as name-value pairs in the URL.
-
This makes debugging easy, but it also makes it easy for users to manipulate
the values.
-
It is limited to the maximum length of the URL.
-
POST sends information via an environment variable.
-
Servlets extend HttpServlet, which extends Servlet.
-
Override doGet() if you wish to process via the GET method.
-
Override doPost() if you wish to process via the POST method.
-
These methods take two arguments:
-
HttpServletRequest: use this to find incoming data.
-
HttpServletResponse: use this to set response information, and to get an
output stream.
-
And they throw two exceptions, which must be caught.
-
ServletException
-
IOException
-
And, you must import these packages:
-
javax.servlet.*;
-
java.io.*;
-
javax.servlet.http.*;
Your First Servlet

Created by: Brandan Jones
December 20, 2001