CS 318 - Week 9 Lab - Intro to Java Servlets
Java abstract class - like in C++,
* implements an abstract concept,
meant to serve JUST as a superclass for subclasses;
HttpServlet is an abstract class.
To create our Java servlets,
we'll create subclasses of this abstract class
public class St10HelloWorld13 extends HttpServlet
* the packages containing Java servlet-related classes
are:
javax.servlet
javax.servlet.http
so, we'll have:
import javax.servlet.*;
import javax.servlet.http.*;
* within your Java servlet,
you are most likely going to implement method(s)
doGet and/or doPost
The appropriate one of these two methods
is called by the web server when a request
for this servlet comes in.
(if the request's method is post, web server
calls doPost --
if the request's method is get, web server
calls doGet)
* the web server packages the request's data
into an object, an HttpServletRequest object
which is one of the arguments to doGet, doPost
* (typically) the servlet tends to output
to an output stream that is related to
doGet's and doPost's second parameter,
an HttpServletResponse object
...and the web server returns the resulting
HttpServletResponse (so streamed into)
to the browser/client/presentation tier
public class St10HelloWorld13 extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
...
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
...
}
}
* the request object has a method,
getParameter
...called with the String containing the name
of a form element,
and it returns a String, a String version of
the value of that element from the request
(from the submitted form)
* see examples!
St10HelloWorld13.java
St10EmpSal.java