|
Java Tools
To develop servlets, I currently use IBM's
VisualAge for Java version 4. When I first
starting using it I found the interface daunting
(however I find notepad tricky to use!), however
now i'm used to it I find it a very good Java
development tool.
There are many other Java tools available,
however rather than go through them all here
I suggest you search the web, ask colleagues,
read books/magazines etc (saves me the typing).
I will be aiming the series at the use of any
tool, however I will probably be adding Visualage
specifics, (ie interface usage stuff) in some
of the articles.
Should anyone find any good links on Java tools
- send them to me and I will put them up on
this site. Likewise if you feel I miss any information
out which would be key/useful for the readers
of this site then feel free to send them to
me.
Structure of a Servlet
When you enter a URL into a browser, a few
things happen. Your browser firstly sends a
request to the specified Web Server and then
that server processes the request and sends
a response back to the browser. The browser
can actually send two types of request, namely
'get' and 'post'.
The 'Get' request is to retrieve information
from the server and the 'Post' request is to
send data to the server (ie a document etc).
When you develop a servlet for use with Domino,
you use the javax.servlet and javax.servlet.http
packages from the Sun JSDK (Java Servlet Development
Kit). However you only need to be concerned
with three methods when developing as everything
else is handled for you. These methods are service(),
doGet(), and doPost().
Whichever Java tool you are using, you would
normally need to 'import' the JSDK into your
environment. If you are using VisualAge, this
can be done by selecting File/QuickStart from
the menu, and then selecting Features/Add Feature
from the QuickStart menu. You will then be presented
with a list of features available and near the
bottom will be a Sun Servlet Development feature
- click on it and ok to install.
Ok back to the three methods. The service()
method is called each time the server requests
a servlet. Usually this method is not used for
Web Server (HTTP) servlets - it is more applicable
to generic servlets - so we will skip this one.
The doPost() method is invoked by all 'post'
requests from the browser and the doGet() method
is invoked by all 'get' requests from the browser.
The format of these methods are as follows:
public void doGet (HttpServletRequest
req, HttpServletResponse res)
public void doPost (HttpServletRequest
req, HttpServletResponse res)
In the above, the HttpServletRequest object
represents the request made to the web server,
and the HttpServletResponse object represents
the response that will be sent to the requester.
As an example, should you be logged on via
session based authentication to your Domino
Server, you can retrieve the current logged
on users name using:
req.getRemoteUser()
Ok thats enough background for now, the next
article will involve developing your first servlet
- the DXTest servlet!
Questions? -
steve.castledine@projectdx.org
|