Skip to content

Commit 3452e59

Browse files
committed
Update jsp-questions.md
1 parent aa14c30 commit 3452e59

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

jsp-questions.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## JSP Interview Questions
1+
# JSP Interview Questions
22

3-
#### Q. What is JSP Implicit Object?
3+
## Q. What is JSP Implicit Object?
44

55
* **request**: This is the HttpServletRequest object associated with the request.
66

@@ -211,10 +211,10 @@ Example:
211211
</body>
212212
</html>
213213
```
214-
#### Q. How JSP pages are processed, from the request to the server to the response to the user?
214+
## Q. How JSP pages are processed, from the request to the server to the response to the user?
215215
When the user `page.jsp` follows the link to the page , he sends an http request to the server `GET /page.jsp`. Then, based on this request and the text of the page itself, the server generates a java class, compiles it and executes the resulting servlet, which forms a response to the user in the form of a representation of this page, which the server redirects back to the user.
216216

217-
#### Q. What are the phases of the JSP life cycle?
217+
## Q. What are the phases of the JSP life cycle?
218218
The JSP life cycle consists of several phases that are managed by the JSP container:
219219

220220
* **Translation** - checking and parsing the JSP page code to create the servlet code.
@@ -225,14 +225,14 @@ The JSP life cycle consists of several phases that are managed by the JSP contai
225225
* **Request Processing** - the long life cycle of processing client requests with a JSP page. Processing is multithreaded and similar to servlets - for each request a new thread, objects are created, `ServletRequest` and the `ServletResponseservice` methods are executed.
226226
* **Destroy** is the last phase of the JSP life cycle in which its class is removed from memory. This usually happens when you turn off the server or unload the application.
227227

228-
#### Q. What are the JSP life cycle methods?
228+
## Q. What are the JSP life cycle methods?
229229
A servlet container (for example, Tomcat, GlassFish) creates a servlet class from a JSP page that inherits interface properties `javax.servlet.jsp.HttpJspBase` and includes the following methods:
230230

231231
* **jspInit()**- the method is declared in the JSP page and is implemented using the container. This method is called once in the JSP life cycle in order to initialize the configuration parameters specified in the deployment descriptor. You can override this method by defining a JSP scripting element and specifying the necessary parameters for initialization;
232232
* **_jspService()**- the method is automatically overridden by the container and corresponds directly to the JSP code described on the page. This method is defined in the interface `HttpJspPage`, its name begins with an underscore, and it differs from other life cycle methods in that it cannot be redefined;
233233
* **jspDestroy()**- the method is called by the container to remove the object from memory (at the last phase of the JSP life cycle is Destroy). The method is called only once and is available for redefinition, providing the ability to free resources that were created in `jspInit()`.
234234

235-
#### Q. How can I prevent direct access to the JSP page from a browser?
235+
## Q. How can I prevent direct access to the JSP page from a browser?
236236
There is no direct access to the directory `/WEB-INF/` from the web application. Therefore, JSP pages can be located inside this folder and thereby restrict access to the page from the browser. However, by analogy with the description of servlets, it will be necessary to configure the deployment descriptor:
237237
```xml
238238
<servlet>
@@ -249,15 +249,15 @@ There is no direct access to the directory `/WEB-INF/` from the web application.
249249
<url-pattern> /example.jsp </url-pattern>
250250
</servlet-mapping>
251251
```
252-
#### Q. What are the main types of JSP tags?
252+
## Q. What are the main types of JSP tags?
253253
* **JSP expression**: `<%= expression %>`- expression that will be processed with redirecting the result to the output;
254254
* **JSP Scriptlet**: `<% code %>`- The code to add to the method service().
255255
* **JSP declaration**: `<%! code %>`- code added to the servlet class body outside the method service().
256256
* **JSP page**`<%@ page att="value" %>` directive: - directives for the servlet container with parameter information.
257257
* **JSP directive include**: `<%@ include file="url" %>`- a file on the local system that is included when translating the JSP into the servlet.
258258
* **JSP Comment**: `<%-- comment --%>`- Comment; ignored when translating a JSP page to a servlet.
259259

260-
#### Q. What are the JSP action tags and JSP Action Elements?
260+
## Q. What are the JSP action tags and JSP Action Elements?
261261
**Action tag** and **JSP Action Elements** provide methods for working with Java Beans, connecting resources, forwarding queries and creating dynamic XML elements. Such elements always begin with recording jsp:and are used directly inside the JSP page without the need for third-party libraries or additional settings.
262262

263263
The most commonly used JSP Action Elements are:
@@ -362,7 +362,7 @@ It specifies the XML declaration or the DOCTYPE declaration of jsp. The XML decl
362362
```jsp
363363
<jsp:output doctype-root-element="" doctype-system="">
364364
```
365-
#### Q. JSP - Servlet - JSP interaction?
365+
## Q. JSP - Servlet - JSP interaction?
366366
"JSP - servlet - JSP" architecture for building applications is called MVC (Model / View / Controller) :
367367

368368
* Model - data classes and business logic;
@@ -384,7 +384,7 @@ PageContext has the following set of features and capabilities:
384384
* mechanisms for sending or including the current request into other application components;
385385
* mechanism for handling exception processes on error page errorpage;
386386

387-
#### Q. What do you know about the JSP Expression Language (EL)?
387+
## Q. What do you know about the JSP Expression Language (EL)?
388388
**JSP Expression Language (EL)** is a scripted expression language that allows you to access Java components (JavaBeans) from JSP. Starting with JSP 2.0, it is used inside JSP tags to separate Java code from the JSP to provide easy access to Java components, while reducing the amount of Java code in JSP pages, or even completely eliminating it.
389389

390390
The development of EL was aimed at making it easier for designers who have minimal knowledge of the Java programming language. Before the advent of the expression language, JSP had several special tags such as scriptlets (English), expressions, etc. that allowed you to write Java code directly on the page. Using an expression language, a web designer only needs to know how to organize the call of the corresponding java methods.
@@ -398,7 +398,7 @@ The JSP 2.0 expression language includes:
398398

399399
An expression language is used inside a construct `${ ... }`. A similar construction can be placed either separately or on the right side of the tag attribute setting expression.
400400

401-
#### Q. How is error handling using JSTL?
401+
## Q. How is error handling using JSTL?
402402
JSTL Core Tags `c:catchand` are used to catch and handle exceptions in the service methods of the class `c:if`.
403403

404404
The tag `c:catchcatches` the exception and wraps it in a variable `exception` available for processing in the tag `c:if`
@@ -411,7 +411,7 @@ The tag `c:catchcatches` the exception and wraps it in a variable `exception` av
411411
Exception Message: ${exception.message}</p>
412412
</c:if>
413413
```
414-
#### Q. How JSP is configured in the deployment descriptor?
414+
## Q. How JSP is configured in the deployment descriptor?
415415
To configure various parameters of JSP pages, an element is used jsp-configthat is responsible for:
416416

417417
* management of scriptlet elements on the page;
@@ -427,13 +427,13 @@ To configure various parameters of JSP pages, an element is used jsp-configthat
427427
</ taglib>
428428
</ jsp-config>
429429
```
430-
#### Q. Is a session object always created on a JSP page, can I disable its creation?
430+
## Q. Is a session object always created on a JSP page, can I disable its creation?
431431
The jsp page, by default, always creates a session. Using a directive pagewith an attribute, sessionyou can change this behavior:
432432

433433
```jsp
434434
<%@ page session ="false" %>
435435
```
436-
#### Q. What is the difference between JSPWriter and PrintWriter?
436+
## Q. What is the difference between JSPWriter and PrintWriter?
437437
`PrintWriter` is the object responsible for recording the contents of the response to the request. `JspWriter` uses an object `PrintWriter` to buffer. When the buffer is full or flushed, it `JspWriter`uses the object `PrintWriter` to write the content in response.
438438

439439
#### Q. How to disable caching on back button of the browser?

0 commit comments

Comments
 (0)