0% found this document useful (0 votes)
12 views42 pages

Java Server Pages (JSP) : November 2020

Uploaded by

pmnittelogisys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views42 pages

Java Server Pages (JSP) : November 2020

Uploaded by

pmnittelogisys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/346016755

Java Server Pages (JSP)

Presentation · November 2020

CITATIONS READS

0 4,950

1 author:

Nilu Singh
K L University
115 PUBLICATIONS 296 CITATIONS

SEE PROFILE

All content following this page was uploaded by Nilu Singh on 19 November
2020.

The user has requested enhancement of the downloaded file.


Java Server Pages (JSP)
JavaServer Pages (JSP) technology provides a
simplified, fast way to create dynamic web
content. JSP technology enables rapid
development of web-based applications that
are server- and platform-independent.

Dr. Nilu Singh


School of Computer Applications
Babu Banarasi Das University
Lucknow-UP
Index

• Serve r Side Scripting(JSP)


• Advantages of JSP
• Lifecycle of a JSP Page
• Example
• Directory structure of JSP
• JSP Scriptlet tag
Introduction
• JSP technology is used to c r e a t e
web application just like Servlet
technology.
• ItServlet
can be thought itof aprovides
because s an extension
more
to
functionality than servlet such as
expression language, JSTL, etc.
• A JSP page consists of HTML tags
and JSP tags.
Cont…
• T h e JSP p a g e s a r e e a sie r to maintain than
Servlet because we can
se p a ra te designing and development.
• It provides so m e additional features such
a s Expression Language, Custom
Tags, etc.
Cont…
• Java Se rv e r P a g e s (JSP) is a technology
which is used to develop web p a g e s
by inserting Java code into the HTML
pages by making special JSP tags.
• T h e JSP tags which allow java code to be
included into it a r e <% - - - - java c o d e - - -
- %>.
• It can consist of either HTML or XML
(combination of both is also possible)
with JSP actions and commands.
Cont…
• It can b e us e d a s HTML page, which
can b e used in forms and registration
pa ge s with the dynamic content into it.
• Dynamic content includes s o m e fields
like dropdown, checkboxes, etc.
whose value will b e fetched from the
database.
Cont…
• This also be used to a c c e s s
can
JavaBeans objects.
• We can s h a r e information a c r o s s pages
using r e q u e s t and r e s p o n s e objects.
• JSP can b e u se d for separation of the
view layer with the business logic in
the web application.
Advantages of J S P (vs. Servlet)

• T h e r e a re many advantages of JSP


over the Servlet, such a s -
 Extension to Servlet
 Easy to maintain
 Fast Development: No need to
recompile and redeploy
 L e s s code than Servlet
Lifecycle of a J S P Page
• T h e JSP pages follow t h e s e p h a s e s -
 Translation of JSP Page
 Compilation of JSP Page
 Classloading (the loads class
classloader file)
 Instantiation (Object of Generated
Servlet
the is created).
 Initialization ( the container invokes
jspInit() method).
 Request processing ( the container
invokes
_jspService() method).
 Destroy ( the container invokes
jspDestroy() method).
Cont…
Example
<html>
<body>
<% out.print(3*9); %>
</body>
</html>
To run a simple J S P Page

Follow the following s t e p s to


execute this JSP page:
 Start the s e r v e r
 Put the JSP file in a folder and deploy on the
server
 Visit the browser by the
URL
http://localhost:portno/contextRoot/jspfile,
for
example,
Note: T h e r e is no need of directory
http://localhost:8888/myapplication/index.jsp
structure if you don't class
TLD files. have files or
Directory structure of J S P
J S P Scripting Elements

• JSP provides the following


scripting elements:
 JSP Comment < % - - comments - - >
 JSP Expression <%= Java Expression %>
 JSP Scriptlet <% Java Statement(s) %>
 JSP Directive <%@ page|include ... %>
J S P Scriptlet tag (Scripting elements)

• In JSP, java code can be written inside


the jsp page using the scriptlet tag.
• The scripting elements provides the
ability to insert java code inside the jsp.
• T h e r e a r e th r e e types of scripting elements:
1. scriptlet tag
2. expression tag
3. declaration tag
Example of J S P scriptlet tag

<html>
<body>
<% out.print("welcome to jsp"); %>
</body>
</html>
Example ( J S P expression tag)
<html>
<body>
<% out.print("welcome to jsp"); %>
</body>
</html>
J S P Declaration Tag

• T h e JSP declaration tag is used to


declare fields and methods.
Syntax T h e syntax of the declaration tag is a s
follows:
<%! field or method declaration %>
Difference between J S P Scriptlet tag
and Declaration tag

Jsp Scriptlet Tag Jsp Declaration Tag

The jsp scriptlet tag can only declare The jsp declaration tag can declare
variables not methods. variables as well as methods.

The declaration of scriptlet tag is placed The declaration of jsp declaration tag is
inside the _jspService() method. placed outside the _jspService() method.
J S P Standard Tag Library (JSTL)
• T h e JSP Standard Ta g Library (JSTL) is
a collection of tag libraries that
implement g e n e r a l - purpose functionality
common to many Web applications.
Note: We will install Java and Jboss s e r v e r on
our machine a s they a r e p r e - requisites to run a
JSP.
Apache Tomcat Server

• JSPs are Internally Compiled Java


into Servlets.
• JSPs, like servlets, are server-
side programs run inside a HTTP server.
• To support JSP/servlet, a J a v a -
capable
HTTP s e r v e r is required.
• http://tomcat.apache.org, is an o p e n -
source software foundation.
Request implicit object

• T h e JSP request is an implicit object of type


HttpServletRequest i.e. created for each jsp
request by the web container.
• It can be used to get request information
such a s parameter, header information,
remote address, s e r v e r name, s e r v e r
port, content type, character encoding etc.
• It can also be used to set, get and
remove attributes from the jsp request scope.
Example
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
Response implicit object

• In JSP, r e s p o n s e is an implicit object of type


HttpServletResponse.
• T h e instance of HttpServletResponse is
created by the web container for each jsp
request.
• It can be used to add or manipulate response
such a s redirect r e s p o n s e to another
resource, send e r r o r etc.
Cont…
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
Client-side scripting and server-
side scripting
Client-side Environment-
 T h e client- side environment used to run
scripts is usually a browser.
 T h e processing takes place on the end u s e r s
computer.
 T h e source code is transferred from the web
s e r v e r to the u s e r s computer over the
internet and run directly in the browser.
Server-side Environment
• A s e r v e r is a computer sy st e m that
s e r v e s a s a central repository of data and
programs and is shared by clients.
• T h e s e r v e r - side environment that runs a
scripting language is a web server.
• A u s e r ' s request is fulfilled by running a
script directly on the web s e r v e r to generate
dynamic HTML pages.
• This HTML is then sent to the client
browser.
Cont…
• It is usually used to provide interactive web
sites that interface to databases or other
data s t o r e s on the server.
• This is different from client- side scripting
w here scripts a r e run by the viewing web
browser, usually in JavaScript.
• T h e primary advantage to s e r v e r - side
scripting is the ability to highly customize
the re sp o n se based on the user's
requirements, a c c e s s rights, or queries into
data stores.
Static sites

Dynamic sites

Server-side and client-side
programming
• Let's s e e the code involved in s e r v e r -
side and client- side programming. In each
case, the code is significantly different:
 T h e y have different purposes and concerns.
 They generally don't u s e the same
programming languages (the exception being
JavaScript, which can be used on the
s e r v e r - and client- side).
 T h e y run inside different operating system
environments.
Client-side programming
• Much like the s e r v e r - side, Client-side
programming is the name for all of the programs
which a r e run on the Client.
Uses:
1. Make interactive webpages.
2. Make stuff happen dynamically on the web page.
3. Interact with temporary storage, and
local storage (Cookies, localStorage).
4. Send r e q u e st s to the server, and retrieve
data from it.
5. Provide a remote service for client- side
applications, such registration,
content delivery, or remote multi-player gaming.
as

software
Cont…
Example languages:
1. JavaScript (primarily)
2. HTML*
3. CSS*
4. Any language running on a client device that
interacts with a remote service is a
client- side language.
 HTML and CSS aren't really "programming
languages" p e r - se. T h e y a r e markup syntax
by which the Client r e n d e r s the page for the
User.
Server-side Programming
• S e r v e r - side programming, is the
general name for the kinds of programs
which are run on the Server.
Uses:
1. P r o c e s s u s e r input.
2. Display pages.
3. Structure web applications.
4. Interact with permanent storage (SQL, files).
Cont…
Example Languages:
1. PHP
2. Python
3. ASP.Net in C#, C + + , or Visual Basic.
4. Nearly any language ( C + + , C#, Java).
T h e s e w e r e not designed specifically for
the task, but a r e now often used for
application- level web services.
What can you do on the server-
side
 Efficient storage and delivery of information
 Customised user experience
 Controlled access to content
 Store session/state information
 Notifications and communication
 Data analysis
Apache Tomcat

• The Apache Tomcat® software is an


open source implementation of the Java
Servlet, JavaServer Pages, Java Expression
Language and Java WebSocket technologies.
• The Java JavaServer Pages, Java
Servlet,
Expression Language and Java WebSocket
specifications are developed under the Java
Community Process.
Cont…
• The Apache Tomcat software is developed in
an open and participatory environment and
released under the Apache License version 2.
• Apache Tomcat software powers numerous
large-scale, mission-critical web applications
across a diverse range of industries and
organizations.
Important Point
• Read about the support for annotations
by Java web tier technologies and how they
can simplify access to resources,
environment data, and life-cycle control.
• Download the final re le a se of the JavaServer
P a g e s Specification, version 2.1. This
version of JavaServer P a g e s technology is
part of the Java EE platform.
• JSP Technology 2.1 In this first article in the
Web Tier to Go with Java EE 5 series, we
discuss the major contributions of
JavaServer P a g e s technology version 2.1 to
the Java EE platform.
Reference
• Apache Tomcat @ http://tomcat.apache.org,
Apache Software Foundation.
• http://java.sun.com/products/jsp.
• https://www.oracle.com/java/technologies/jspt.html
• https://www3.ntu.edu.sg/home/ehchua/programming/jav
a/JSPByExample.html
• https://www.javatpoint.com/jsp-tutorial
• https://www.guru99.com/jsp-tutorial.html
• https://www.guru99.com/install-j s p -j b o s s -s e r v e r -
java.html
• https://developer.mozilla.org/en-
US/ doc s / L e a r n/ Se r ve r- side/First_steps/Introduction
• https://computersciencewiki.org/index.php/Client-
side_scripting_and_server- side_scripting
View publication stats

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy