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
}
%>