Posts

9. Servlet Interview Questions

  || Servlet Interview Questions || 1. What is servlet? Servlet is a server side programming language which is used for generating dynamic web pages. It generates web-page as a response of the request received from client(browser). 2. Static webpage vs Dynamic webpage? The webpages which are same for all the users are static webpages and the webpages that are dynamically generated based on the user’s request (that may be different for each user depending on the request) are known as dynamic webpages. Servlet is mainly used for dynamic webpages. 3. Life cycle of a servlet? Following the the stages of servlet life cycle: 1) Loading of Servlet class: The servlet container finds the servlet class mentioned in web.xml file and loads it. 2) Servlet instantiation: The object of servlet class gets created in this phase. 3) Initialization: Servlet initialization by calling init() method. 4) Servicing the request: In this phase the servlet service the client request by calling the service() me

8. Working of Servlet and useful Interfaces terms

  Working of Servlet How Servlet Works? 1) When the web server (e.g. Apache Tomcat) starts up, the servlet container deploy and loads all the servlets. During this step Servlet container creates ServletContext object. ServletContext is an interface that defines the set of methods that a servlet can use to communicate with the servlet container. Note: There is only one ServletContext per webapp which is common to all the servlets. ServletContext has several useful methods such as addListener(), addFilter() etc. For now I am not explaining them as I will cover them in a separate text about ServletContext. 2) Once the servlet is loaded, the servlet container creates the instance of servlet class. For each instantiated servlet, its init() method is invoked. 3) Client (user browser) sends an Http request to web server on a certain port. Each time the web server receives a request, the servlet container creates HttpServletRequest and HttpServletResponse objects. The HttpServletRequest object

7. Servlet Life Cycle

 Servlet Life Cycle Servlet life cycle can be described as a series of steps through which a servlet goes during its life span, starting from loading till it gets destroyed. Web Server: It is also known as HTTP Server, it can handle HTTP Requests send by client and responds the request with an HTTP Response. | -  Web Container: Also known as Servlet Container and Servlet Engine. It is a part of Web Server that interacts with Servlets. This is the main component of Web Server that manages the life cycle of Servlets. Servlet life cycle contains five steps:  1) Loading of Servlet  2) Creating instance of Servlet  3) Invoke init() once  4) Invoke service() repeatedly for each client request  5) Invoke destroy() Step 1: Loading of Servlet When the web server (e.g. Apache Tomcat) starts up, the servlet container deploy and loads all the servlets. Step 2: Creating instance of Servlet Once all the Servlet classes loaded, the servlet container creates instances of each servlet class. Servle

6. Servlet Introduction and Servlet API

 Servlet Introduction Servlet is a java program that runs inside JVM on the web server. It is used for developing dynamic web applications. Features of Servlet - Platform Independence: Servlets are written in Java, making them platform-independent and capable of running on any server that supports the Java platform. - Server-side Execution: Servlets execute on the server, allowing them to handle business logic, database operations, and other server-side tasks. - Multithreading Support: Servlets can handle multiple requests simultaneously through the use of multithreading, improving efficiency and responsiveness. - Security: Servlets benefit from Java's built-in security features, including the ability to define and enforce access controls. - Portable and Reusable: Servlets can be developed and deployed independently of the underlying server, promoting code reusability and portability across different environments. Way to create Servlet 1. By extending HttpServlet class 2. By extend

5. JSP Interview Questions

  || JSP Interview Questions || 1.  What is JSP? A) JSP stands for Java Server Pages, it is a server side technology which is used for creating dynamic web pages. It is the extension of servlets.  Q) What does dynamic web page means here?    - The web pages that are generated based on user’s response and may be different for each user are called dynamic web pages unlike the static web pages that are same for every user no matter how they interact with the application. Q) What does Server side technology means?  - There are basically two types of technologies: client-side and Server-side. Client-side means that the action takes place on the user’s (the client’s) computer. Server-side means that the action takes place on a web server (the place where you have stored all your JSP pages). 2. What are JSP life cycle phases? A) A JSP page goes through the below phases: 1) Compilation: In this phase the JSP code gets converted into the equivalent servlet code. 2) Initialization: The convert

4. Implicit Object in JSP

  Implicit Object in  JSP Implicit objects in JSP (JavaServer Pages) are pre-defined objects that are automatically available to developers without the need for explicit declarations. These objects play a crucial role in simplifying the development process by providing access to various aspects of the JSP environment.  1. request:    - Represents the client's request to the server.    - Provides access to parameters submitted with the request, such as form data or query parameters.    - Example: `request.getParameter("parameterName");` 2. response:    - Represents the server's response to the client.    - Allows manipulation of the response, such as setting headers or sending content back to the client.    - Example: `response.getWriter().write("Hello, World!");` 3. out:    - Refers to the output stream and is used to send content to the client.    - Simplifies the process of writing dynamic content within the HTML page.    - Example: `<%@ page contentTyp

3. JSP Action Tag and Expression Language

  JSP Actions Tag – Java Server Pages - The use of Action Tags is for controlling the behavior of the Servlet Engine. Action Tags are used during the processing phase of a request. - Action Tags allow the dynamic insertion of code into JSP. They start with 'jsp:'. Directives vs Actions - Directives are used during translation phase while actions are used during request processing phase. - Unlike Directives Actions are re-evaluated each time the page is accessed. List of JSP ACtion Tags : <jsp:include> <jsp:forward> <jsp:param> <jsp:useBean> <jsp:setProperty> <jsp:getProperty> <jsp:plugin> <jsp:fallback> <jsp:body> <jsp:element> <jsp:attribute> <jsp:text> JSP (JavaServer Pages) action tags are special tags used in JSP to perform specific actions or operations. They provide a way to include external content, control page flow, work with JavaBeans, and more. Let's go through each of the mentioned JSP actio