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

LECTURE 5 & 6 - JAVA SERVER PAGES

Associate Degree in Information Technology


AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

LECTURE 5 - AIOOP23111
Java Server Pages
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Java Server Pages


• Java Server Pages (JSP) is a technology that allows developers
to create dynamic web pages using a combination of HTML,
XML, and Java code.
• JSP pages are executed on a web server, and the resulting
output is sent to the client's web browser.
• JSP provides a way to easily access Java code and objects from
within a web page, simplifying the creation of dynamic web
pages.
• JSP pages are typically used in conjunction with Java servlets,
which handle data processing and client requests. JSP is part
of the Java EE platform and is supported by most web servers
and servlet containers.
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Java server pages


•A JSP page is a file with a ".jsp" extension that can
contain a combination of HTML Tags and JSP codes.
•To create a web page, JSP uses a combination of HTML or
XML markup, JSP tags, expressions, and Java code.
•JSP tags begin with <% and end with %>.
•JSP expressions are used to insert dynamic content into
the page and begin with <%= and end with %>.
•JSP can use JavaBeans to store and retrieve data.
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The five scripting elements


• Comment <%-- Set of comment statements --%>
• Directive <%@ directive %>
• Declaration <%! declarations %>
• Scriptlet <% scriplets %>
• Expression <%= expression %>
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Scripting element comment


• JSP comment marks text or statements that the
JSP container should ignore.
• A JSP comment is useful when you want to hide
or "comment out", a part of your JSP page.
• Examples
- java comment //this is a comment
-html <!--this is a comment-->
-jsp <%-- this is a comment -- %>
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Scripting element-directive
• These tags are used to provide specific instructions to the
web container when the page is translated.
• provide directions and instructions to the container, telling it
how to handle certain aspects of the JSP processing
• For example, a directive can be used to import java classes.
• The three subcategories for directives are:
-Page: <%@ page ... %>
-Include: <%@ include ... %>
-Taglib: <%@ taglib ... %>
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The page directive


• is used to provide instructions to the container.
These instructions pertain to the current JSP
page.
• page directives are coded at the top of the JSP
page
<%@ include file = "relative url" >
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The include directive


• This directive tells the container to merge the content of other
external files with the current JSP during the translation phase.
• You may code the include directives anywhere in your JSP
page.
• The filename in the include directive is actually a relative URL
• if you just specify a filename with no associated path, the JSP
compiler assumes that the file is in the same directory as your
JSP.
• It works more like a hyperlink to other pages
• <%@include file=“file name”%>
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The taglib directive


• The JSP taglib directive is implemented to
define a tag library with "taglib" as its prefix.
Custom tag sections of JSP use taglib.
• JSP's taglibdirective is used as standard tag
libraries.
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Scripting element –declaration


• it is used to declare methods and variables you
will use in your Java code within a JSP file.
• According to the rules of JSP, any variable must
be declared before it can be used.
• Example :
-in java we declare int data = 50;
-in jsp we declare <%int data=50;%>
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Scripting element-Scriptlets
• scriptlet tag allows writing Java code
statements within the JSP page
• it evaluates your Java expression but does not
print or show your result in conjunction with
the HTML created.
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Scripting element-Expression
• are responsible for containing scripting language expression,
which gets evaluated and converted to Strings by the JSP
engine.
• mostly used for printing the values of variables or methods in
the form of output.
• you are not required to write out.print() for writing your data
• Example
-in java we use system.out.print (“im printing”);
-in jsp we use <% im print %>
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Simple jsp that will display a date


LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Creating a jsp page


• Please click the following link that contains the
step by step method in creating a the jsp page
• This video will help you attempt Example 2

• https://drive.google.com/file/d/1RqTuDtwCTsP
YZdAw1evv9nmg5GdboFle/view?usp=drive_lin
k
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Example 2
• Then do the following example
• Create a JSP page that will have the following
-display a date
-a button that will take you to the login
page
-that will include information from the
myinclude page
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The main page


LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The login page


LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

The myinclude page


• This is the page that will be included in the
main page to display a certain information in
the main page
LECTURE 5 & 6 - JAVA SERVER PAGES
Associate Degree in Information Technology
AIOOP23111- OBJECT ORIENTED PROGRAMMING 2
Year 3_Semester: 05
From Jan 2024 to May 2024

Resources
• J2EE Developer’s Guide –
http://java.sun.com/j2ee/j2sdkee/techdocs/gui
des/ejb/html/DevGuideTOC.html
• J2EE Tutorial –
http://java.sun.com/j2ee/tutorial/1_3-fcs/index
.html
• Server Side Programming –
http://www.theserverside.com

You might also like