Java Unit 3 Lecture 29
Java Unit 3 Lecture 29
2
JAVA SERVER PAGE (JSP)
What is JSP?
• Java Server Pages (JSP) is a technology which is used to develop web
pages by inserting Java code into the HTML pages by making special JSP
tags.
• The JSP tags which allow java code to be included into it are <% ----java
code----%>.
• It is a server side technology.
• It is used for creating web application.
• It is used to create dynamic web content.
• It is an advanced version of Servlet Technology.
• It is a Web based technology helps us to create dynamic and platform
independent web pages.
• In this, Java code can be inserted in HTML/ XML pages or both.
• JSP is first converted into servlet by JSP container before processing the
client’s request.
Servlet Vs JSP
Servlets – JSP –
• Servlet is a Java program which • JSP program is a HTML code which
supports HTML tags too. supports java statements too.To be
• Generally used for developing more precise, JSP embed java in
business layer(the complex html using JSP tags.
computational code) of an • Used for developing presentation
enterprise application. layer of an enterprise application
• Servlets are created and maintained • Frequently used for designing
by Java developers. websites and used by web
developers.
JSP syntax
1.Declaration Tag :-It is used to declare variables.
Syntax:- <%! Dec var %>
Example:- <%! int var=10; %>
• The scripting elements provides the ability to insert java code inside the jsp. There
are three types of scripting elements:
• scriptlet tag
• expression tag
• declaration tag
JSP Scriplet tag
• A scriptlet tag is used to execute java source code in JSP.
Syntax is as follows:
• <% java source code %>
Example:
• <html>
• <body>
• <% out.print("welcome to jsp"); %>
• </body>
• </html>
JSP expression tag
• The code placed within JSP expression tag is written to the
output stream of the response. So you need not write
out.print() to write data. It is mainly used to print the values
of variable or method.
• Syntax of JSP expression tag
• <%= statement %>
• Example:
• <html>
• <body>
• <%= "welcome to jsp" %>
• </body>
• </html>
JSP Declaration Tag
• The JSP declaration tag is used to declare fields and methods.
• The code written inside the jsp declaration tag is placed outside
the service() method of auto generated servlet.
• So it doesn't get memory at each request.
• The syntax of the declaration tag is as follows:
• <%! field or method declaration %>
• Example:
• <html>
• <body>
• <%! int data=50; %>
• <%= "Value of the variable is:"+data %>
• </body>
• </html>
Summary
. Discussed about Java Server Pages (JSP).
. Discussed about JSP Architecture.
. Discussed about JSP Life Cycle.
15
Home Work
Q1. What are the life-cycle methods for a JSP?
16
References
Text Book
• Herbert Schildt (2019), “Java The Complete Reference, Ed. 11, McGraw-Hill .
17
THANK YOU
For queries
Email: kushagra.e13465@cumail.in