You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jsp-questions.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
##JSP Interview Questions
1
+
# JSP Interview Questions
2
2
3
-
####Q. What is JSP Implicit Object?
3
+
## Q. What is JSP Implicit Object?
4
4
5
5
***request**: This is the HttpServletRequest object associated with the request.
6
6
@@ -211,10 +211,10 @@ Example:
211
211
</body>
212
212
</html>
213
213
```
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?
215
215
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.
216
216
217
-
####Q. What are the phases of the JSP life cycle?
217
+
## Q. What are the phases of the JSP life cycle?
218
218
The JSP life cycle consists of several phases that are managed by the JSP container:
219
219
220
220
***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
225
225
***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.
226
226
***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.
227
227
228
-
####Q. What are the JSP life cycle methods?
228
+
## Q. What are the JSP life cycle methods?
229
229
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:
230
230
231
231
***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;
232
232
***_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;
233
233
***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()`.
234
234
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?
236
236
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:
237
237
```xml
238
238
<servlet>
@@ -249,15 +249,15 @@ There is no direct access to the directory `/WEB-INF/` from the web application.
249
249
<url-pattern> /example.jsp </url-pattern>
250
250
</servlet-mapping>
251
251
```
252
-
####Q. What are the main types of JSP tags?
252
+
## Q. What are the main types of JSP tags?
253
253
***JSP expression**: `<%= expression %>`- expression that will be processed with redirecting the result to the output;
254
254
***JSP Scriptlet**: `<% code %>`- The code to add to the method service().
255
255
***JSP declaration**: `<%! code %>`- code added to the servlet class body outside the method service().
256
256
***JSP page**`<%@ page att="value" %>` directive: - directives for the servlet container with parameter information.
257
257
***JSP directive include**: `<%@ include file="url" %>`- a file on the local system that is included when translating the JSP into the servlet.
258
258
***JSP Comment**: `<%-- comment --%>`- Comment; ignored when translating a JSP page to a servlet.
259
259
260
-
####Q. What are the JSP action tags and JSP Action Elements?
260
+
## Q. What are the JSP action tags and JSP Action Elements?
261
261
**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.
262
262
263
263
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
"JSP - servlet - JSP" architecture for building applications is called MVC (Model / View / Controller) :
367
367
368
368
* Model - data classes and business logic;
@@ -384,7 +384,7 @@ PageContext has the following set of features and capabilities:
384
384
* mechanisms for sending or including the current request into other application components;
385
385
* mechanism for handling exception processes on error page errorpage;
386
386
387
-
####Q. What do you know about the JSP Expression Language (EL)?
387
+
## Q. What do you know about the JSP Expression Language (EL)?
388
388
**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.
389
389
390
390
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:
398
398
399
399
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.
400
400
401
-
####Q. How is error handling using JSTL?
401
+
## Q. How is error handling using JSTL?
402
402
JSTL Core Tags `c:catchand` are used to catch and handle exceptions in the service methods of the class `c:if`.
403
403
404
404
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
411
411
Exception Message: ${exception.message}</p>
412
412
</c:if>
413
413
```
414
-
####Q. How JSP is configured in the deployment descriptor?
414
+
## Q. How JSP is configured in the deployment descriptor?
415
415
To configure various parameters of JSP pages, an element is used jsp-configthat is responsible for:
416
416
417
417
* management of scriptlet elements on the page;
@@ -427,13 +427,13 @@ To configure various parameters of JSP pages, an element is used jsp-configthat
427
427
</ taglib>
428
428
</ jsp-config>
429
429
```
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?
431
431
The jsp page, by default, always creates a session. Using a directive pagewith an attribute, sessionyou can change this behavior:
432
432
433
433
```jsp
434
434
<%@ page session ="false" %>
435
435
```
436
-
####Q. What is the difference between JSPWriter and PrintWriter?
436
+
## Q. What is the difference between JSPWriter and PrintWriter?
437
437
`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.
438
438
439
439
#### Q. How to disable caching on back button of the browser?
0 commit comments