<section>
  <header>
    <product>resin</product>
    <title>Simple JSP page</title>
    <type>example</type>
    <resin-2.0>$resin/java_tut/add_page.xtp</resin-2.0>
    <brief>
      A simple JSP page
    </brief>
    <description>
      A simple JSP page that adds 2+2 and displays the result in the
      browser.
    </description>
  </header>

<p>The sample page you'll be creating adds 2&nbsp;+&nbsp;2 and displays the
result in the browser.</p>

<p>JSP pages are created by putting a <var/add.jsp/> file in the
document directory.  The JSP page is a mixture of HTML and Java
code.  Resin's JSP engine compiles the .jsp file into a Java
servlet and then runs the servlet to produce the output.</p>

<p>Resin's web server stores its pages in a directory named doc.  On
this machine it's
<var><jsp:expression>
   application.getContext("/").getRealPath("/")
</jsp:expression></var></p>

<p>Create the text file <var>doc/test/add.jsp</var>
(<jsp:expression>
  application.getContext("/").getRealPath("test/add.jsp")
</jsp:expression>) with your favorite text editor: notepad, emacs, vi,
or whatever.
It should contain the following text:</p>

<example title='add.jsp'>
2 + 2 = &lt;%= 2 + 2 %&gt;
</example>

<p>To see Resin in action, you need to look at the page in the
browser.  The URL is
http://<jsp:expression>
request.getServerName() + ":" + request.getServerPort()
</jsp:expression>/test/add.jsp</p>

<p>If everything works, you should see the following page:</p>

<results>
2 + 2 = 4
</results>

<section title='An explanation'>

<p>The web server uses the '.jsp' extension to make 'add.jsp' an active
page.  For HTML pages and GIF files, the web server just copies the
file from your computer to the browser.  That's why looking at
the file index.html in your browser looks the same as looking at 
http://localhost:8080/index.html.</p>

<p>By default, Resin copies text to the browser.  For example, Resin
copied the '2 + 2 = ' to the browser.  In fact, if you wrote a JSP
file with no special tags, Resin would copy it entirely to the
browser; it would be equivalent to an '.html' file.  Resin is smart
enough to see that the page is static, so it can avoid working hard.</p>

<p>The special tags '&lt;%' and '%&gt;' tell Resin to do something
active, something script related.   You will only need to learn a few
of these special tags:</p>

<deftable>
<tr><th>Tag<th>Meaning
<tr><td>&lt;%@ ... %&gt;<td>Directive
<tr><td>&lt;%= ... %&gt;<td>Java expression
<tr><td>&lt;% ... %&gt;<td>Java function
<tr><td>&lt;%! ... %&gt;<td>Java declaration
</deftable>

<p>In the add.jsp example, 
the expression tags, e.g. <code>&lt;%= 2 + 2 %&gt;</code>, tell Resin
to evaluate the text as a Java expression and print the result
to the browser.  In this case, 4.</p>

</section>
</section>


