O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required