When init() and Distroy() will be called

init() is called whenever the servlet is loaded for the first time into the webserver.it performs certain one time activities which are required during the lifetime of the servlet.It may be some initialisation of variables or a database connection. Destroy will be called whenever the servlet is removed from the webserver. Various resources which are … Read more

What is use of parseQueryString

Parses a query string and builds a hashtable of key-value pairs, where the values are arrays of strings. The query string should have the form of a string packaged by the GET or POST  method. In Advanced Java, particularly in the context of web development using technologies like Servlets or JavaServer Pages (JSP), the parseQueryString … Read more

What is the use of setSecure() and getSecure() in Cookies

setSecure method indicates to the web browser that the cookie should only be sent using a secure protocol (https). getSecure method returns the value of the ‘secure’ flag. As of my last knowledge update in January 2022, there is no standard method named setSecure() or getSecure() specifically in the Java Servlet API for handling cookies. … Read more

What is the Difference in using Request.getRequestDispatcher() and context.getRequestDispatcher()

getRequestDispatcher(path): In order to create it we need to give the relative path of the resource getRequestDispatcher(path):In order to create it we need to give the absolute path of the resource. In Java EE (Enterprise Edition) or Jakarta EE, the request.getRequestDispatcher() and context.getRequestDispatcher() methods are used to obtain a RequestDispatcher object, but they are associated … Read more

Difference Between ServletContext and ServletConfig

ServletConfig:  One ServletConfig Object is created per servlet It can be used to access ServletContext Parameters are configured in DD(deployment description) ServletContext One ServletContext will be created per web application. Can be used to access web app parameter. Can be used to get server Info. In Java web development, both ServletContext and ServletConfig are important components, … Read more