Useful google terms:

jsp tomcat

Useful Sun JAVA API:

Java2 Platform, Enterprise Edition, v 1.3 API Specification

Code Zones:

Directives:

JSP objects

JSPs and Threads

Java System Properties

Using Java Classes in JSPs:

LINUX:arnow> pwd       # See? I'm in my source directory
/home/arnow/src
LINUX:arnow> ls -l      # I have one project now: proj1
total 4
drwxr-x---  3 arnow arnow 4096 Oct 16 13:32 proj1
LINUX:arnow> ls -lR       # Let's see what's here ...
.:
total 4
drwxr-x---  3 arnow arnow 4096 Oct 16 13:32 proj1

./proj1:
total 4
drwxr-x---  2 arnow arnow 4096 Oct 23 04:53 util

./proj1/util:
total 4
-rw-r-----  1 arnow arnow 90 Oct 16 13:34 Cow.java
LINUX:arnow> cd proj1/util      # OK, better compile Cow.java
LINUX:arnow> cat Cow.java       # but let's take a peek first ...
package proj1.util;
public class Cow {
public static String getSound() {return "moo";}
}
LINUX:arnow> javac Cow.java       # note that it's in the package proj1.util!
LINUX:arnow> pwd                  # corresponds to its location in the src project directory:
/home/arnow/src/proj1/util
LINUX:arnow> ls -l                # so? is there a class file now?
total 8
-rw-r-----  1 arnow arnow 275 Oct 23 04:54 Cow.class
-rw-r-----  1 arnow arnow  90 Oct 16 13:34 Cow.java
LINUX:arnow> cd ../..            # jump up two levels to source to create a jar file for deployment
LINUX:arnow> jar cf proj1.jar ./proj1        # create the jar file for tomcat
LINUX:arnow> ls -l
total 8
drwxr-x---  3 arnow arnow 4096 Oct 16 13:32 proj1
-rw-r-----  1 arnow arnow 1090 Oct 23 04:56 proj1.jar
LINUX:arnow> jar tvf proj1.jar         # what's in the jar ???
     0 Thu Oct 23 00:56:50 EDT 2008 META-INF/
    71 Thu Oct 23 00:56:50 EDT 2008 META-INF/MANIFEST.MF
     0 Thu Oct 16 09:32:22 EDT 2008 proj1/
     0 Thu Oct 23 00:54:46 EDT 2008 proj1/util/
    90 Thu Oct 16 09:34:46 EDT 2008 proj1/util/Cow.java
   275 Thu Oct 23 00:54:46 EDT 2008 proj1/util/Cow.class
LINUX:arnow>      # the java file doesn't belong there, but won't hurt!
LINUX:arnow> cp proj1.jar $HOME/tomcat/webapps/proj1/WEB-INF/lib        # deploy the jar
LINUX:arnow> cd $HOME/tomcat/webapps/proj1/
LINUX:arnow> cat t2.jsp        # a jsp that uses Cow:
<br><br><br>
QUESTION: WHAT DOES A COW SAY?<br>
ANSWER:  <%= proj1.util.Cow.getSound() %>
LINUX:arnow> cat t3.jsp        # another jsp that uses Cow, unqualified:
<%@ page import="proj1.util.*" %>
<br><br><br>
QUESTION: WHAT DOES A COW SAY?<br>
ANSWER:  <%= Cow.getSound() %>
LINUX:arnow>

JSP TRANSLATION TO JAVA: Original JSP:

here's the results of some java .... <br/><br/>

<%
        int k=5;
        k += 27;
        out.print("here is k "+k+"<br/>\n");
%>

more regular html plaintext stufff <br><br>

<%
        k -= 10;
        out.print("here is k again: "+k+"<br>\n");
%>
one more thing: <%= "Today is "+(new java.util.Date())%>

JSP TRANSLATION TO JAVA: Java Code Produced by Tomcat

:

package org.apache.jsp;

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

public final class t1_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.List _jspx_dependants;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                  null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("here's the results of some java .... <br/><br/>\n");
      out.write("\n");

    int k=5;
    k += 27;
    out.print("here is k "+k+"<br/>\n");

      out.write("\n");
      out.write("\n");
      out.write("more regular html plaintext stufff <br><br>\n");
      out.write("\n");

    k -= 10;
    out.print("here is k again: "+k+"<br>\n");

      out.write("\n");
      out.write("one more thing: ");
      out.print( "Today is "+(new java.util.Date()));
      out.write('\n');
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}