Servlets are the pure Java solution to handle web requests. Many application will use servlets instead of JSP and others will use servlets in conjunction with JSP. 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 . On this machine, you'll put the Java source in . WEB-INF/classes is the standard location for servlets and other Java classes. 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 recompilation and the error reporting.Create the following servlet in with your favorite text editor: notepad, emacs, vi, or whatever. (On this machine, )
Now browse the servlet at http://jsp.kyokuto.co.jp:80/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 URL tells Resin to look for a servlet.
The default resin.conf in the distribution is already configured for the example, so you can just start Resin as described in the standalone server. Not all of the standard resin.conf is necessary for this example, though. You can cut it down to the following configuration. For development, using the invoker is convenient. The invoker servlet will let you specify the servlet class in the URL itself, like /servlet/test.HelloWorld. Its configuration in the resin.conf looks like:
Resin allows a short cut for the XML configuration in the example above; you can use XML attributes in place of elements. The Servlet 2.3 standard uses only elements. So the servlet-mapping configuration following the Servlet 2.3 standard would look like:
The two are entirely equivalent. For larger configurations, using attributes makes the resin.conf or web.xml more readable.
This example just uses the default virtual host and root web-app. Many sites will just use the default virtual host and root web-app. For now, you can ignore them and concentrate on the other configuration. The example configuration is a complete working configuration. You can create a configuration file in resin-2.0.x/conf/test.conf to test it out.
If you run into any trouble trying to start Resin, look at the standalone HTTP server page.
|