Class 2 |
Intermediate Java 30-IT-397 |
|
Your First Servlet
-
In NetBeans/Forte, open a project or create a new one.
-
Choose the directory in which you want to put your source code.
-
Choose New-Servlet, and you will see that a great deal of the effort is
completed for you!
-
Including the content-type, which tells the browser that the output will
be HTML. You can change this if you wish.
-
Let's write a simple HelloWhirled servlet.
-
The action will be taken in a method called processRequest(HttpServletRequest,
HttpServletResponse).
-
Both doPut() and doGet() will call processRequest().
-
So, all you need to do is un-comment the generated HTML, and put a statement
in an out.println().
-
out is an object of type java.io.PrintWriter that sends our output to the
response to the web browser. Use it just as you would
System.out.println().
-
HelloWhirled.java
-
The output:
The Servlet Life Cycle

Created by: Brandan Jones
December 20, 2001