Web Engineering in UOE
Web Engineering in UOE
JSP Life Cycle is defined as translation of JSP Page into servlet as a JSP Page needs
to be converted into servlet first in order to process the service requests. The Life
Cycle starts with the creation of JSP and ends with the disintegration of that.
Different phases of JSP Life Cycle
When the browser asks for a JSP, JSP engine first checks whether it needs to compile
the page. If the JSP is last compiled or the recent modification is done in JSP, then the
JSP engine compiles the page.
Compilation process of JSP page involves three steps:
Parsing of JSP
Turning JSP into servlet
Compiling the servlet
JSP Lifecycle is depicted in the below diagram.
Following steps explain the JSP life cycle:
1. Translation of JSP page
2. Compilation of JSP page(Compilation of JSP page into
_jsp.java)
3. Classloading (jsp.java is converted to class file jsp.class)
4. Instantiation(Object of generated servlet is created)
5. Initialisation(jspinit() method is invoked by container)
6. Request Processing(jspservice() method is invoked by the
container)
7. Destroy (_jspDestroy() method invoked by the container)
Let us have more detailed summary on the above points:
1. Translation of the JSP Page:
A Java servlet file is generated from a JSP source file. This is the first step of JSP life
cycle. In translation phase, container validates the syntactic correctness of JSP page
and tag files.
The JSP container interprets the standard directives and actions, and the custom
actions referencing tag libraries (they are all part of JSP page and will be
discussed in the later section) used in this JSP page.
In the above pictorial description, demo.jsp is translated to demo_jsp.java in the
first step
Let's take an example of "demo.jsp" as shown below:
Demo.jsp
1. <html>
2. <head>
3. <title>Demo JSP</title>
4. </head>
5. <%
6. int demvar=0;%>
7. <body>
8. Count is:
9. <% Out.println(demovar++); %>
10. <body>
11. </html>
Here you can see that in the screenshot theOutput is 1 because demvar is
initialized to 0 and then incremented to 0+1=1
In the above example,
demo.jsp, is a JSP where one variable is initialized and incremented. This JSP
is converted to the servlet (demo_jsp.class ) wherein the JSP engine loads the
JSP Page and converts to servlet content.
When the conversion happens all template text is converted to println()
statements and all JSP elements are converted to Java code.
This is how a simple JSP page is translated into a servlet class.
2. Compilation of the JSP Page
The generated java servlet file is compiled into java servlet class
The translation of java source page to its implementation class can happen at
any time between the deployment of JSP page into the container and processing
of the JSP page.
In the above pictorial description demo_jsp.java is compiled to a class file
demo_jsp.class
3. Classloading
Servlet class that has been loaded from JSP source is now loaded into the
container
4. Instantiation
In this step the object i.e. the instance of the class is generated.
The container manages one or more instances of this class in the response to
requests and other events. Typically, a JSP container is built using a servlet
container. A JSP container is an extension of servlet container as both the
container support JSP and servlet.
A JSPPage interface which is provided by container provides init() and destroy
() methods.
There is an interface HttpJSPPage which serves HTTP requests, and it also
contains the service method.
5. Initialization
6. public void jspInit()
7. {
8. //initializing the code
}
_jspinit() method will initiate the servlet instance which was generated from
JSP and will be invoked by the container in this phase.
Once the instance gets created, init method will be invoked immediately after
that
It is only called once during a JSP life cycle, the method for initialization is
declared as shown above
6. Request processing
7. void _jspservice(HttpServletRequest request HttpServletResponse response)
8. {
9. //handling all request and responses
}
_jspservice() method is invoked by the container for all the requests raised by
the JSP page during its life cycle
For this phase, it has to go through all the above phases and then only service
method can be invoked.
It passes request and response objects
This method cannot be overridden
The method is shown above: It is responsible for generating of all HTTP
methods i.eGET, POST, etc.
7. Destroy
8. public void _jspdestroy()
9. {
10. //all clean up code
}
_jspdestroy() method is also invoked by the container
This method is called when container decides it no longer needs the servlet
instance to service requests.
When the call to destroy method is made then, the servlet is ready for a garbage
collection
This is the end of the life cycle.
We can override jspdestroy() method when we perform any cleanup such as
releasing database connections or closing open files
4
Understanding Context… seeking to understand the
issues, opportunities or situation from multiple
perspectives….
There are many different approaches for seeking to understand the context
in which programming is being developed and delivered. No one way is
right… rather certain approaches may be selected based on your focus and
resources. Below are brief descriptions of various approaches. Many of
these approaches can be mixed and matched!
Needs assessment is a specific approach that focuses on the systematic
collection of data from stakeholders related to their needs or perceived needs.
There are various methods that can be used to conduct a needs assessment.
What holds them together conceptually is that the guiding questions for the
investigation are framed around potential participant “needs.” Needs assessment
is often used as a general and universal term for data collection related to
program planning, however like all approaches, it is has strengths and
limitations.
3
Session
A session creates a file in a temporary directory on the server where registered session variables
and their values are stored. This data will be available to all pages on the site during that visit.
A session ends when the user closes the browser or after leaving the site, the server will terminate
the session after a predetermined period of time, commonly 30 minutes duration.
Cookies
Cookies are text files stored on the client computer and they are kept of use tracking purpose.
Server script sends a set of cookies to the browser. For example name, age, or identification number
etc. The browser stores this information on a local machine for future use.
When next time browser sends any request to web server then it sends those cookies information to
the server and server uses that information to identify the user.
2
Request Redirects
A redirect is a way to forward visitors and search engines from one URL to another.
This is useful when moving content to a new URL, when deleting pages or when
changing domain names or merging websites.
Whenever possible avoid using redirects, but when you have to use them, make sure
to follow these best practices:
Avoid chained redirects: one redirect should not forward to another redirect.
Redirect to the preferred version of your website, using the right protocol (http or
https), domain name (www or non-www) and path notation (with or without
trailing slash).
Use a 302-redirect for inactive campaigns.
Use a 301-redirect for content that's permanently removed.
Persistence
Definition - What does Persistence mean?
Persistence refers to object and process characteristics that continue to exist even after
the process that created it ceases or the machine it is running on is powered off. When
an object or state is created and needs to be persistent, it is saved in a non-volatile
storage location, like a hard drive, versus a temporary file or volatile random access
memory (RAM).
[NEW] Techopedia Resources | Browse Industry Leading Software Used by Techopedia Staff and Users
Daily
The RequestDispatcher interface provides the facility of dispatching the request to another
resource it may be html, servlet or jsp. This interface can also be used to include the
content of another resource also. It is one of the way of servlet collaboration.
1
JavaScript
JavaScript is a programming language commonly used in web
development. It was originally developed by Netscape as a means to
add dynamic and interactive elements to websites. While JavaScript is
influenced by Java, the syntax is more similar to C and is based on
ECMAScript, a scripting language developed by Sun Microsystems.
JavaScript is a client-side scripting language, which means the source
code is processed by the client's web browser rather than on the web
server. This means JavaScript functions can run after a webpage has
loaded without communicating with the server. For example, a
JavaScript function may check a web form before it is submitted to
make sure all the required fields have been filled out. The JavaScript
code can produce an error message before any information is actually
transmitted to the server.
Like server-side scripting languages, such as PHP and ASP, JavaScript
code can be inserted anywhere within the HTML of a webpage.
However, only the output of server-side code is displayed in the HTML,
while JavaScript code remains fully visible in the source of the
webpage. It can also be referenced in a separate .JS file, which may
also be viewed in a browser.
Below is an example of a basic JavaScript function that adds two
numbers. The function is called with the parameters 7 and 11. If the
code below were included in the HTML of a webpage, it would display
the text "18" in an alert box.
<script>
function sum(a,b)
{
return a + b;
}
var total = sum(7,11);
alert(total);
</script>
Request Type
PropertiesSection
Request.cache Read only
Contains the cache mode of the request (e.g., default, reload, no-cache).
Request.context Read only
Contains the context of the request (e.g., audio, image, iframe, etc.)
Request.credentials Read only
Contains the credentials of the request (e.g., "omit", "same-origin", "include"). The
default is "same-origin".
Request.destination Read only
Returns a string from the RequestDestination enum describing the request's destination.
This is a string indicating the type of content being requested.
Request.headers Read only
Contains the mode of the request (e.g., cors, no-cors, same-origin, navigate.)
Request.redirect Read only
Contains the mode for how redirects are handled. It may be one of follow, error,
or manual.
Request.referrer Read only
Stores a Boolean that declares whether the body has been used in a response yet.
Life cycle is same as question no 5