This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Jsp expecting Static reference to execute java function

Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All;

While I am writing following code in java; and then executing this code in jsp page to have counter of every on load jsp page..

package admin;

public class pageCount {

public int counter;

public int getCounter(){
System.out.println("INSIDE *****");
return counter;



So i am calling above code in jsp page as follows..

<%@page import="admin.pageCount;"%>

The page is
out.println(pageCount.getCounter()); // this says can not make static reference to non static method getCounter() from the pageCount

To make above code of Jsp properly runnable i need to make public int counter and getCounter() method static..

My query is why we need to make variable in java code as static to access the same in jsp page..

Hope to hear on this soon...

Thanking you in advance.

Best Regards;
Posts: 67424
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

Also, at this point in time, putting Java code into a JSP is considered an poor and antiquated practice. You'd do yourself an immense service by learning modern JSP techniques.
Destroy anything that stands in your way. Except this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic