Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 33

JSP

JavaServer
Pages
The Typical Web
server, different
clients connecting
via the Internet to
a Web server. In
this example, the
Web server is
running on Unix
and is the very
popular Apache
Web server.
First static web pages were displayed.
Afterwards Perl and C were languages used on
the web server to provide dynamic content.
Soon most languages including Visualbasic,
Delphi, C++ and Java could be used to write
applications that provided dynamic content using
data from text files or database requests.
These were known as CGI server side
applications.
ASP was developed by Microsoft to allow HTML
developers to easily provide dynamic content
supported as standard by Internet Information
Server (IIS).
JSP was developed by Sun Microsystems.
Introduction to Java Server
Pages
 JavaServer Pages (JSP) is a technology
based on the Java language and enables
the development of dynamic web sites.
JSP was developed by Sun Microsystems
to allow server side development. JSP
files are HTML files with special Tags
containing Java source code that provide
the dynamic content.
HTML

JSP
JAVA
JSP source code runs on the web server in the JSP Servlet Engine. The JSP
Servlet engine dynamically generates the HTML and sends the HTML output to
the client's web browser…
Why use JSP?

JSP is easy to learn and allows developers to


quickly produce web sites and applications in an
open and standard way. JSP is based on Java,
an object oriented language. JSP offers a robust
platform for web development.

Main reasons to use JSP:


Multi platform (windows n unix)
Component reuse by using Javabeans and EJB.
Advantages of Java.
What are Java Server
Pages?
Conceptually seen as “scripts”
Adopt more procedural style of coding
OO techniques are still possible
Adopt a modern web development style
Simplified syntax
Many built-in short-cuts
Text files containing
HTML
Java code
You can take one JSP file and move it to another platform, web
server or JSP Servlet engine.
Moving JSP file from one platform to another.
HTML and graphics displayed on the web browser are classed as the
presentation layer..

JavaServer Pages

Implementation

JSP
Java
presentation
developer
s
web designers
Advantages of Servlets

Efficient: threads instead of OS processes, one


servlet copy, persistence
Convenient: lots of high-level utilities
Powerful: talking to server, sharing data, pooling,
persistence
Portable: run on virtually all operating systems and
servers
Secure: no shell escapes, no buffer overflows
Inexpensive: inexpensive plug-ins if servlet
support not bundled
Problems with Servlets
Servlet development requires high-level of
understanding of many concepts
Too much overhead in development cycle
(implementation n design concatenated)
Limited built-in productivity mechanisms
Clunky syntax (unorganised)
Advantages of JSP
Versus ASP: better language for dynamic part,
portable
Versus PHP: better language for dynamic part
Versus pure servlets: more convenient to create
HTML
Versus SSI: much more flexible and powerful
Versus JavaScript: server-side, richer language
Versus static HTML: dynamic features
JSP or Servlets: How do I choose?
Servlets JSP
Servlets usage JSP usage
Minimal HTML generation Complex HTML
Somewhat constant logic Dynamic logic
Complex Java logic “simple” Java logic
Servlet disadvantages JSP disadvantages
No pre-built set of reusable Can get messy
components Can be misused
Hard to maintain when HTML
intensive
Require Java expertise
Development cycle
Servlet benefits JSP benefits
Complete control Pre-built components
Advanced development Expression language
Flexible Convenience features
Requires minimal Java knowledge
Development cycle
Flexible
JSP architecture
JSPs are built on top of SUN's servlet technology.
JSPs are essential an HTML page with special JSP tags
embedded. These JSP tags can contain Java code.
The JSP file extension is .jsp rather than .htm or .html.
The JSP engine parses the .jsp and creates a Java
servlet source file. It then compiles the source file into a
class file, this is done the first time and this why the JSP
is probably slower the first time it is accessed.
Any time after this the special compiled servlet is
executed and is therefore returns faster.
Steps required for a JSP request:
1. The user goes to a web site made using JSP. The user goes to a
JSP page (ending with .jsp). The web browser makes the request
via the Internet.
2. The JSP request gets sent to the Web server.
3. The Web server recognises that the file required is special (.jsp),
therefore passes the JSP file to the JSP Servlet Engine.
4. If the JSP file has been called the first time, the JSP file is parsed,
otherwise go to step 7.
5. The next step is to generate a special Servlet from the JSP file. All
the HTML required is converted to println statements.
6. The Servlet source code is compiled into a class.
7. The Servlet is instantiated, calling the init and service methods.
8. HTML from the Servlet output is sent via the Internet.
9. HTML results are displayed on the user's web browser.
Installing a software
 Java 2 Standard addition Software
Development Kit(J2SE SDK)
 Apache Jakarta Tomcat
 Tomcat is known as servlet container. In java,
world, servlet container is responsible for
receiving web requests and passing them to
the java web application.
JSP Syntax Tags
 6 primary JSP syntax tags
<%-- … --%>
Comment
Server side comment style
Single or multi-line
<%@ … %>
Directive
Used to describe page characteristics
Provides execution information to container
<%! … %>
Declaration
Used to declare variables or methods
Can inadvertently create a non-thread safe JSP
JSP Syntax Tags [cont.]
 6 primary JSP syntax tags
<% … %>
Scriptlet
Used to apply “business logic” to HTML generation
Typically intermixed with HTML throughout page
<%= … %>
Expression
Used to convert Java value into HTML text
Easy way to write out a value
<jsp:…> … </jsp:…>
JSP action
Predefined executable tags
Simplifies JSP syntax
JSP Development
Like writing an HTML document
JSP has its own set of tags
Contains HTML presentation logic
Includes conditional Java logic
Can include JavaScript or XML
Normally stored in a .jsp file
Handles request
Generates response
Free Servlet and JSP Software
Tomcat: http://jakarta.apache.org/
JSWDK:
http://java.sun.com/products/servlet/download.ht
ml
JRun: http://www.allaire.com/products/jrun/
ServletExec: http://newatlanta.com/
LiteWebServer: http://www.gefionsoftware.com/
Java Web Server:
http://www.sun.com/software/jwebserver/try/
Thank You

Queries???

You might also like