aspose file tools*
The moose likes JSP and the fly likes Jsp expecting Static reference to execute java function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp expecting Static reference to execute java function" Watch "Jsp expecting Static reference to execute java function" New topic
Author

Jsp expecting Static reference to execute java function

Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
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 *****");
counter++;
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;
Brijesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsp expecting Static reference to execute java function