Contents
- Translation of JSP page to Servlet.
- Compilation of JSP page(Compilation of JSP into test. …
- Classloading (test. …
- Instantiation(Object of the generated Servlet is created)
- Initialization(jspInit() method is invoked by the container)
- Request processing(_jspService()is invoked by the container)
7. Which one is the correct order of phases in JSP life cycle? Explanation: The correct order is Compilation, Initialization, Execution, Cleanup.
In Servlet first init() is called then service() and at last destroy() is called automatically when a servlet object is created. Activities in android have lifecycle methods onCreate() ,onStart(), onResume() etc which are automatically called when object of an activity come into existence.
Three methods are central to the life cycle of a servlet. These are init(),service() and destroy(). They are implemented by every servlet and are invoked at a specific time by the server.
A JSP life cycle is defined as the process from its creation till the destruction. This is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.
Let’s learn different phases of JSP Life Cycle Compilation process of JSP page involves three steps: Parsing of JSP. Turning JSP into servlet. Compiling the servlet.
Directives are elements that relay messages to the JSP container and affect how it compiles the JSP page. The directives themselves do not appear in the XML output. There are three directives: include, page, and taglib.
There are four techniques used in Session tracking: Cookies. Hidden Form Field. URL Rewriting.
JSP handles this type of requests using getParameter() method to read simple parameters and getInputStream() method to read binary data stream coming from the client.
There are mainly three life cycle methods of a servlet, which we can describe as: init() service() destroy()
There are three life cycle methods of a Servlet : init() service() destroy()
The servlet is initialized by calling the init() method. The servlet calls service() method to process a client’s request. The servlet is terminated by calling the destroy() method. Finally, servlet is garbage collected by the garbage collector of the JVM.
Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses the Java programming language.
forward() method | sendRedirect() method |
---|---|
The forward() method works at server side. | The sendRedirect() method works at client side. |
It sends the same request and response objects to another servlet. | It always sends a new request. |
Method | Description |
---|---|
public void destroy() | is invoked only once and indicates that servlet is being destroyed. |
public ServletConfig getServletConfig() | returns the object of ServletConfig. |
public String getServletInfo() | returns information about servlet such as writer, copyright, version etc. |
- Directive Tag: Directive tags provide general information about the JSP page to the JSP engine. …
- Declaration Tag: …
- Scriptlet Tag: …
- Expression Tag: …
- Action Tag: …
- Comment Tag:
JSP Model 2 is a complex design pattern used in the design of Java Web applications which separates the display of content from the logic used to obtain and manipulate the content. Since Model 2 drives a separation between logic and display, it is usually associated with the model–view–controller (MVC) paradigm.
- Expression Tags.
- Scriptlet Tags.
- Declaration Tags.
- Step 1: The client navigates to a file ending with the . …
- Step 2: If the compiled version of JSP exists in the web server, it returns the file. …
- Step 3: The JSP Engine loads the JSP file and translates the JSP to Servlet(Java code). …
- Step 4: The JSP engine compiles the Servlet to an executable . …
- Step 5: The .
- Summary of lifecycle events.
- JSP page translation (validation, translation, compilation phases)
- Load Class.
- Instantiate.
- jspInit method is called.
- _jspService method is called.
- jspDestroy method is called.
- Important points to remember.
There are 9 jsp implicit objects. These objects are created by the web container that are available to all the jsp pages. The available implicit objects are out, request, config, session, application etc.
S.No.Directive & Description1<%@ page … %> Defines page-dependent attributes, such as scripting language, error page, and buffering requirements.2<%@ include … %> Includes a file during the translation phase.3<%@ taglib … %> Declares a tag library, containing custom actions, used in the page
JSP directives are the messages to JSP container. They provide global information about an entire JSP page. JSP directives are used to give special instruction to a container for translation of JSP to servlet code. In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.
JSP directives are the elements of a JSP source code that guide the web container on how to translate the JSP page into it’s respective servlet. Syntax : @ <%@ directive attribute = “value”%> Directives can have a number of attributes which you can list down as key-value pairs and separated by commas.
JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer can call them directly without being explicitly declared. JSP Implicit Objects are also called pre-defined variables.
The main difference between a session and a cookie is that session data is stored on the server, whereas cookies store data in the visitor’s browser. Sessions are more secure than cookies as it is stored in server. Cookie can be turned off from browser.
JSP plays the role of presentation of the data and controller. It is an interface between model and view while model connects both to the controller as well as the database. Main business logic is present in the model layer.
- Inside the <%code fragment%> scriptlet use the request object, that is an instance of a javax. …
- Use the getMethod() API method of javax. …
- Use the getRequestURI() API method of javax.
Declaration tag is one of the scripting elements in JSP. This Tag is used for declare the variables. Along with this, Declaration Tag can also declare method and classes.
getParameter() – Passing data from client to JSP The request. getParameter() is being used here to retrieve form data from client side.
The applet life cycle can be defined as the process of how the object is created, started, stopped, and destroyed during the entire execution of its application. It basically has five core methods namely init(), start(), stop(), paint() and destroy(). These methods are invoked by the browser to execute.
- init()
- start()
- paint()
- stop()
- destroy()
A – The destroy() method is called only once at the end of the life cycle of a servlet.
The doGet() method is used for getting the information from server while the doPost() method is used for sending information to the server.
Explanation: command directive is not a directive in JSP.
JavaServer Pages (JSP) is a Java standard technology that enables you to write dynamic, data-driven pages for your Java web applications. JSP is built on top of the Java Servlet specification. The two technologies typically work together, especially in older Java web applications.
Servlet can accept all protocol requests, including HTTP, while JSP can only accept HTTP requests. In MVC architecture, servlet works as a controller while JSP works as a view for displaying output. … Whereas in JSP, business logic is split from presentation logic using JavaBeans.
void destroy() Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet’s service method have exited or after a timeout period has passed.
Q 24 – Which of the following is true about Initialization phase in JSP life cycle? A – When a container loads a JSP it invokes the jspInit method before servicing any requests. B – Container invokes _jspService method during Initialization phase.
JavaServer Pages (JSP) is a technology for developing Webpages that supports dynamic content. … A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role of a user interface for a Java web application.