example.servlet.basic
Class HelloServlet

java.lang.Object
  |
  +--HttpServlet
        |
        +--example.servlet.basic.HelloServlet

public class HelloServlet
extends HttpServlet

Introduces servlets with the hello, world example.

Most servlets will extend HttpServlet and implement the doGet method. Servlets which handle POST request will implement the doPost method.

Resin maps the calling URL to the servlet using the <servlet-mapping> configuration in the resin.conf or web.xml.

For example, this servlet is called with the URL /tutorial/servlet/example.servlet.basic.HelloServlet. That mapping is configured in the doc/tutorial/WEB-INF/web.xml with the special "invoker" servlet:

 <servlet-mapping>
   <url-pattern>/servlet/*</url-pattern>
   <servlet-name>invoker</servlet-name>
 </servlet-mapping>
 

Every URL matching /servlet/* will use the invoker. The invoker finds the classname "example.servlet.basic.HelloServlet" following the /servlet, instantiates it and sends it the request.

This servlet belongs in WEB-INF/classes/example/servlet/basic/HelloServlet.java. In the standard Resin installation, it will be something like resin-2.0.2/doc/java_tut/WEB-INF/...

When the servlet .java file is changed, Resin will automatically recompile it. It's a good idea to go to the HelloServlet.java and modify it (change the string to "Hi, World"), to get the basic idea.

See Also:
Serialized Form

Constructor Summary
HelloServlet()
           
 
Method Summary
 void doGet(HttpServletRequest request, HttpServletResponse response)
          Handles GET requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HelloServlet

public HelloServlet()
Method Detail

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws java.io.IOException,
                  ServletException
Handles GET requests. Resin will call the doGet method when the browser sends a GET request.

Parameters:
request - the request object contains the data from the browser's request.
response - the response object contains methods to send data back to the browser.
java.io.IOException
ServletException