caucho
Resin
FAQ
Reference Guide
JavaDoc
Demo
Tutorial

JSP page
Config
URLs
Database Forms
XTP Copy
Hello Tag
Vary Filter
HardCore
Mailing Forms
Beans
Cache
XSL Filter
run-at

Servlet
Parse Errors
Runtime Errors
Debugging
 Adding a servlet

JSP page
JSP page
Parse Errors

Servlets are the pure Java solution to handle web requests. Experienced JSP programmers use servlets in conjunction with JSP to create clearer and simpler applications. The servlets handle Java processing: form handing, calculation and database queries. JSP formats the results.

Servlets belong in doc/WEB-INF/classes. On this machine, you'll put the Java source in C:\resin-2.0.2\doc\java_tut\WEB-INF\classes.

Create the following servlet in WEB-INF/classes/test/HelloWorld.java with your favorite text editor: notepad, emacs, vi, or whatever. (On this machine, C:\resin-2.0.2\doc\java_tut\WEB-INF\classes\test\HelloWorld.java)

test/HelloWorld.java
package test;

import java.io.*;

import javax.servlet.http.*;
import javax.servlet.*;

public class HelloWorld extends HttpServlet {
  public void doGet (HttpServletRequest req,
                     HttpServletResponse res)
    throws ServletException, IOException
  {
    res.setContentType("text/html");

    PrintWriter pw = res.getWriter();

    pw.println("Hello, world!");
    pw.println("<br>Init: " + getInitParameter("my.info"));
    pw.close();
  }
}

Now browse the servlet at http://www.jfrn.gov.br:83/java_tut/servlet/test.HelloWorld. Resin will automatically compiles the servlet for you. Browsing servlets differs from page browsing because you're executing a servlet class, not looking at a page. The /servlet URL tells Resin to look for a servlet.

Resin automatically reloads and recompiles servlets, beans, and classes placed in WEB-INF/classes. You should make some changes and add errors to become familiar with Resin's error reporting.

Configuration

For development, using the /servlet invoker is convenient. Its configuration in the resin.conf looks like

<caucho.com>
<http-server>
  <servlet-mapping url-pattern='/servlet/*'
                   servlet-name='invoker'/>
</http-server>
</caucho.com>

When deploying a web site, it's a good idea to disable the servlet invoker for security reasons. You can configure Resin to invoke your servlet directly. The following example will call the HelloWorld servlet using just the /hello url.

For many servlet you'll also want to configure init parameters. In the hello example, you can set the my.info parameter as follows:

<caucho.com>
<http-server>
  <servlet-mapping url-pattern='/hello'
                   servlet-name='hello-world'/>
  <servlet servlet-name='hello-world'
           servlet-class='test.HelloWorld'>
    <init-param my.info='My Init Param'/>
  </servlet>
</http-server>
</caucho.com>

JSP page
JSP page
Parse Errors
Copyright © 1998-2001 Caucho Technology. All rights reserved.
Copyright © 1998-2001 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.