top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Can we define a class in a JSP Page?

+1 vote
58 views
Can we define a class in a JSP Page?
posted Aug 23, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

It’s not a good practice though, but we can define a class inside a JSP Page. Below is the sample code for this:

<%!
private static class NestedClass { //static is better because Servlet is multi-threaded
  private final int num = 0;
  public int getNum() {
    return num;
  }
}
%>

Or

<%      
    class Person { 
        //this will go inside method body, so can't be public
    }
%>
answer Sep 7, 2017 by Manikandan J
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...