186 javax.servlet.http.HttpSession is interface, then How can you say, object created for inteface H

Опубликовано: 10 Май 2020
на канале: tech fort
148
2

Question : javax.servlet.http.HttpSession is interface, then How can you say the object created for inteface HttpSession :
----------------------------------------------------------------------
(becasue in java Interface does not allow to create object.)
Answer : HttpSession object means it is the object of underlaying server container supplied java class that implements javax.servlet.http.HttpSession interface.

objectReference.getClass().getName();
getClass() method returns a Class object that represents the object's class.
getName() method returns the name of that class as a string.

getClass(), getName() methods are belongs to Object class.

Ex: "Hello String".getClass().getName(); will return java.lang.String
HttpSession session=request.getSession();
String className=session.getClass().getName();
out.println("HttpSession implemented class name is "+className);

javax.servlet.http.HttpSession interface implemented Sub Class Name is in Tomcat Server (container supplies) :

org.apache.catalina.session.StandardSessionFacade