Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Servlets belong in WEB-INF/classes. On this machine, the source is in Java source in /var/www/hosts/www.caucho.com/webapps/resin-3.0/WEB-INF/classes. 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.</p> <p>Create the following servlet in WEB-INF/classes/test/HelloServlet.java with your favorite text editor: notepad, emacs, vi, or whatever. (On this machine, /var/www/hosts/www.caucho.com/webapps/resin-3.0/WEB-INF/classes/test/HelloServlet.java)</p> <p>WEB-INF/classes/test/HelloServlet.java</p> <p>package test;</p> <p>import java.io.*;</p> <p>import javax.servlet.http.*;</p> <pre><code>import javax.servlet.*; public class HelloServlet extends HttpServlet { public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { PrintWriter out = res.getWriter(); out.println("Hello, world!"); out.close(); } } </code></pre> <p>Now browse the servlet at /resin-3.0/hello. 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 /hello URL is configured for the hello, world servlet below.</p> <p>Configuration</p> <p>Configuration for the servlet is in the WEB-INF/web.xml file.</p> <p>The servlet needs to be configured and it needs to be mapped to a URL. The tag configures the servlet. In our simple example, we just need to specify the class name for the servlet.</p> <p>The tag specifies the URLs which will invoke the servlet. In our case, the /hello URL invokes the servlet. Because the tutorial webapp is a sub-URL like /doc/servlet/tutorial/helloworld, the actual URL to invoke the servlet is the combination of the two.</p> <p>WEB-INF/web.xml</p> <pre><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd"&gt; &lt;servlet&gt; &lt;servlet-name&gt;hello&lt;/servlet-name&gt; &lt;servlet-class&gt;test.HelloServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;hello&lt;/servlet-name&gt; &lt;url-pattern&gt;/hello&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload