The JSP doesn’t recognize the Counter class

The Counter class is in the foo package, but there’s nothing in the JSP to acknowledge that. It’s the same thing that happens to you with any other Java code, and you know the rule: import the package or use the fully-qualified class name in your code.

image with no caption

Counter.java

package foo;

public class Counter {
   private static int count;
   public static int getCount() {
       count++;
       return count;
   }
}

JSP code was:

<% out.println(Counter.getCount()); %>

JSP code should be:

image with no caption

Get Head First Servlets and JSP, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.