JSP Flashcards

1
Q

What is JSP?

A

JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the JSP life cycle?

A

Translation of JSP to Servlet code.
Compilation of Servlet to bytecode.
Loading Servlet class.
Creating servlet instance.
Initialization by calling jspInit() method
Request Processing by calling _jspService() method
Destroying by calling jspDestroy() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is JSP Compilation?

A

When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine compiles the page.

The compilation process involves three steps:

Parsing the JSP.

Turning the JSP into a servlet.

Compiling the servlet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is JSP Initialization?

A

When a container loads a JSP it invokes the jspInit() method before servicing any requests. If you need to perform JSP-specific initialization, override the jspInit() method:

public void jspInit(){
  // Initialization code...
}

Typically initialization is performed only once and as with the servlet init method, you generally initialize database connections, open files, and create lookup tables in the jspInit method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is JSP Execution?

A

This phase of the JSP life cycle represents all interactions with requests until the JSP is destroyed.

Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the _jspService() method in the JSP.

The _jspService() method takes an HttpServletRequest and an HttpServletResponse as its parameters as follows:

void _jspService(HttpServletRequest request, 
                 HttpServletResponse response)
{
   // Service handling code...
}
The _jspService() method of a JSP is invoked once per a request and is responsible for generating the response for that request and this method is also responsible for generating responses to all seven of the HTTP methods ie. GET, POST, DELETE etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is JSP Cleanup?

A

The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container.

The jspDestroy() method is the JSP equivalent of the destroy method for servlets. Override jspDestroy when you need to perform any cleanup, such as releasing database connections or closing open files.

The jspDestroy() method has the following form:

public void jspDestroy()
{
   // Your cleanup code goes here.
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a JSP scriptlet?

A

A JSP scriptlet is used to contain any code fragment that is valid for the scripting language used in a page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is JSP Expression Language?

A

JSP Expression Language (EL) makes it possible to easily access application data stored in JavaBeans components. JSP EL allows you to create expressions both (a) arithmetic and (b) logical. Within a JSP EL expression, you can use integers, floating point numbers, strings, the built-in constants true and false for boolean values, and null.

${expr}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

JSP Scripting Element: Declaration

A

A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

JSP Scripting Element: Directive

A

A JSP directive affects the overall structure of the servlet class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

JSP Scripting Element: Scriptlet

A

A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JSP Scripting Element: Expression

A

A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to precompile JSP?

A

In the web.xml tag, instead of using , use to register the JSP. As with a servlet, you can use the tag within the servlet tag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to use JSP with web.xml?

JSP Mapping

A

JSPs are kind of servlet. JSP pages are compiled into servlet. This servlet run in the servlet container provided by any java web server.

In web.xml, tag used to name the name servlet class and jsp file. Then you can map those servlet and jsp file according to your own URLs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is MVC?

A

MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application’s concerns.

Model - Model represents an object or JAVA POJO carrying data. It can also have logic to update controller if its data changes.

View - View represents the visualization of the data that model contains.

Controller - Controller acts on both model and view. It controls the data flow into model object and updates the view whenever data changes. It keeps view and model separate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the Front Controller?

A

The front controller design pattern is used to provide a centralized request handling mechanism so that all requests will be handled by a single handler. This handler can do the authentication/ authorization/ logging or tracking of request and then pass the requests to corresponding handlers. Following are the entities of this type of design pattern.

Front Controller - Single handler for all kinds of requests coming to the application (either web based/ desktop based).

Dispatcher - Front Controller may use a dispatcher object which can dispatch the request to corresponding specific handler.

View - Views are the object for which the requests are made.

https://www.tutorialspoint.com//design_pattern/front_controller_pattern.htm