Chapter 16: JavaServer Pages: Part II

pages 1 - 16

Writing JavaBeans

  1. Write a bean. A bean is a reusable, platform independent component.
  2. Place the code in this directory: C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes
  3. At the DOS prompt, compile the file with: javac -d . name.java. Note: if javac is not in your classpath, follow the instructions here
  4. Place a jsp file in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT or any of its subdirectories.
  5. Start Apache Tomcat. Note: it is very important to start Tomcat after the WEB-INF\classes directory has been created so that Tomcat can find relevant packages.
  6. Load the above .jsp file into Apache Tomcat.

Relevant JSP Commands

JavaBean Scope

The scope attribute specifies how long a bean exists in memory. The scopes will be demonstrated with Counter.java.

Shopping Cart Example

Exercise