Review: Getting Started
(Continued)
Main servlet code goes in doGet or doPost:
The HttpServletRequest contains the incoming
information
The HttpServletResponse lets you set outgoing
information
Call setContentType to specify MIME type
Call getWriter to obtain a Writer pointing to client
One time setup code goes in init
Servlet gets initialized and loaded once
Servlet gets invoked multiple times
97
Servlets
www.corewebprogramming.com
Review: Handling Form Data
(Query Data)
Query data comes from HTML forms as
URL encoded name/value pairs
Servlets read data by calling
request.getParameter("name")
Results in value as entered into form, not as sent over
network. I.e. not URL encoded.
Always check for missing or
malformed data
Special case: query data that contains special HTML
characters
Need to be filtered if query data will be placed
into resultant HTML page
98
Servlets
www.corewebprogramming.com
49