Saturday, November 9, 2019

Difference Betwixt Servletconfig Together With Servletcontext Inwards Jsp Servlet J2ee

Difference betwixt ServletConfig and ServletContext
ServletContext and ServletConfig these 2 are of import interface of Servlet API which is used yesteryear Java J2EE programmer during spider web application development. Correct agreement of What is ServletContext and ServletConfig is real of import for whatever J2EE application developer. Apart from that Difference betwixt ServletContext and ServletConfig are a popular Servlet JSP interview questions in addition to generally asked on both fresher in addition to experienced Java programmer during J2EE interviews. Both ServletContext in addition to ServletConfig are basically configuration objects which are used yesteryear servlet container to initialize diverse parameter of spider web application. But they accept around divergence inward price of scope in addition to availability thence get-go nosotros come across what is ServletContext in addition to ServletConfig objects are in addition to and then nosotros volition come across difference betwixt ServletConfig in addition to ServletContext inward Java J2EE.


What is ServletConfig inward JSP Servlet
these 2 are of import interface of Servlet API which is used yesteryear Java J Difference betwixt ServletConfig in addition to ServletContext inward JSP Servlet J2EEServletConfig  in an interface inward Servlet API in addition to ServletConfig object represents or used to initialize unmarried servlet inward web application yesteryear servlet container. Inside deployment descriptor known every bit web.xml,  we define Servlet initialization parameter related to that servlet within <init-param></init-param> tag. its a gear upwardly of advert /value pair. Following is signature of ServletConfig interface :

public interface ServletConfig

By using ServletConfig in addition to combination of init-param you lot tin post away configure whatever Servlet inward J2EE environment.




What is ServletContext inward Servlet JSP
ServletContext is fifty-fifty to a greater extent than of import than ServletConfig in addition to its ane per spider web application, every bit good known every bit Context. This object is mutual for all the servlet in addition to they operate this object to communicate amongst the servlet container to larn the special of whole spider web application or execution surround of import affair to holler back is, it represents a spider web application inward unmarried JVM.

Signature: public interface ServletContext

By using ServletContext object you lot tin post away portion objects to whatever Servlet or JSP inward whole spider web application. See how to larn ServletContext inward Servlet JSP in addition to Struts to uncovering out unlike ways of getting ServletContext inward J2EE application.


Difference betwixt ServletContext vs ServletConfig

Now let’s come across divergence betwixt ServletContext and ServletConfig in Servlets JSP inward tabular format

Servlet Config
Servlet Context
Servlet config object correspond unmarried servlet
It correspond whole spider web application running on special JVM in addition to mutual for all the servlet
Its similar local parameter associated amongst special servlet
Its similar global parameter associated amongst whole application
It’s a advert value span defined within the servlet department of web.xml file thence it has servlet broad orbit
ServletContext has application broad orbit thence define exterior of servlet tag inward web.xml file.
getServletConfig() method is used to larn the config object
getServletContext() method is  used to larn the context object.
for illustration shopping cart of a user is a specific to special user thence hither nosotros tin post away operate servlet config
To larn the MIME type of a file or application session related information is stored using servlet context object.

That’s all on What is ServletContext, What is ServletConfig in addition to What are differences betwixt ServletContext in addition to ServletConfig inward J2EE environment. Most of import divergence to holler back is that ServletContext is per spider web application piece ServletConfig is per servlet basis. ServletContext is every bit good refer every bit application orbit inward JSP

Further Learning
Difference betwixt PATH in addition to Classpath inward Java

No comments:

Post a Comment