SlideShare a Scribd company logo
JSP & STRUTS
#122065
#122076
#122107
#122139
#122141
#122199
JSP -Java Server Pages
The purpose of a servlet is to create a Web page in
response to a client request
Servlets are written in Java, with a little HTML mixed in
JSP is an alternate way of creating servlets
 JSP is written as ordinary HTML, with a little Java mixed in
 The Java is enclosed in special tags .
 The HTML is known as the template text
JSP files must have the extension .jsp
2
JSP scripting elements
There is more than one type of JSP “tag”
depending on what you want done with the Java
<%= expression %>
 The expression is evaluated and the result is inserted into
the HTML page
<% code %>
 The code is inserted into the servlet's service method
 This construction is called a scriptlet
 <%! declarations %>
 The declarations are inserted into the servlet class, not into
a method
3
4
Example JSP
<HTML>
<BODY>
Hello! The time is now <%= new java.util.Date() %>
</BODY>
</HTML>
Notes:
 The <%= ... %> tag is used, because we are computing a value and
inserting it into the HTML
 The fully qualified name (java.util.Date) is used, instead of the short
name (Date).
Variables
You can declare your own variables, as usual
JSP provides several predefined variables
 request : The HttpServletRequest parameter
 response : The HttpServletResponse parameter
 session : The HttpSession associated with the request, or
null if there is none
 out : A JspWriter (like a PrintWriter) used to send output
to the client
Example:
 Your hostname: <%= request.getRemoteHost() %>
5
Scriptlets
Scriptlets are enclosed in <% ... %> tags
 Scriptlets do not produce a value that is inserted directly into
the HTML (as is done with <%= ... %>)
 Scriptlets are Java code that may write into the HTML
 Example:
<% String queryData = request.getQueryString();
out.println("Attached GET data: " + queryData); %>
Scriptlets are inserted into the servlet exactly as
written, and are not compiled until the entire servlet is
compiled
6
Declarations
Use <%! ... %> for declarations to be added to
servlet class, not to any particular method
 Servlets are multithreaded, so nonlocal variables must be
handled with extreme care
 If declared with <% ... %>, variables are local and OK
 Data can also safely be put in the request or session objects
Example:
<%! private int accessCount = 0; %>
Accesses to page since server reboot:
<%= ++accessCount %>
Use <%! ... %> to declare methods as easily as to
declare variables
7
JSP in XML
JSP can be embedded in XML as well as in HTML
Due to XML’s syntax rules, the tags must be different (but
they do the same things)
HTML: <%= expression %>
XML: <jsp:expression>expression</jsp:expression>
HTML: <% code %>
XML: <jsp:scriptlet>code</jsp:scriptlet>
HTML: <%! declarations %>
XML: <jsp:declaration>declarations</jsp:declaration>
HTML: <%@ include file=URL %>
XML: <jsp:directive.include file="URL"/>
8
Struts
 Struts is an open-source framework for building more
flexible, maintainable and structured front-ends in Java
web applications
 There are two key components in a web application:
the data and business logic performed on this data
the presentation of data
 Struts
helps structuring these components in a Java web app.
controls the flow of the web application, strictly separating these
components
unifies the interaction between them
9
Why struts are useful
structural separation of data presentation and business logic
Struts provides a Controller that manages the control flow
easy localization
based on standard Java technologies
open-source
10
THANK YOU !!!
11

More Related Content

PPT
Jsp intro
PPT
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
PPT
Web&java. jsp
PPT
29 Jsp
PPTX
jQuery basics
PPTX
Controllers & actions
PPT
2310 b 06
Jsp intro
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Web&java. jsp
29 Jsp
jQuery basics
Controllers & actions
2310 b 06

What's hot (20)

PPT
Java script
PDF
Asp.Net MVC - Razor Syntax
PPT
Java script
PDF
Rest hello world_tutorial
PDF
How to Create and Load Model in Laravel
PPT
Ajax
PPTX
Designing CakePHP plugins for consuming APIs
DOCX
Html To JSP
PPT
2310 b 13
PPTX
Java Script
DOCX
servlet programming
PPT
ASP.NET 03 - Working With Web Server Controls
DOCX
Java server pages
PPT
2310 b 03
PDF
Lab work servlets and jsp
PPTX
Introduction to Javascript
PPTX
Learn html and css from scratch
PPTX
Java script
PPTX
Lecture6
Java script
Asp.Net MVC - Razor Syntax
Java script
Rest hello world_tutorial
How to Create and Load Model in Laravel
Ajax
Designing CakePHP plugins for consuming APIs
Html To JSP
2310 b 13
Java Script
servlet programming
ASP.NET 03 - Working With Web Server Controls
Java server pages
2310 b 03
Lab work servlets and jsp
Introduction to Javascript
Learn html and css from scratch
Java script
Lecture6
Ad

Similar to Jsp & struts (20)

PPTX
Java Server Pages
PPTX
PPT
PPT
Jsp sasidhar
PPT
JSP diana y yo
PPTX
JSP AND XML USING JAVA WITH GET AND POST METHODS
PDF
Jsp servlets
PPS
Jsp element
PPTX
Introduction - Java Server Programming (JSP)
PPTX
C:\fakepath\jsp01
PPTX
JSP.pptx
PPTX
JSP- JAVA SERVER PAGES
PDF
Introduction to JSP pages
PPTX
21CS642 Module 4_2 JSP PPT.pptx VI SEM CSE
PPT
J2EE - JSP-Servlet- Container - Components
PPTX
Advance java session 10
PPTX
Module 3.pptx.............................
PPTX
Introduction to JSP
PPTX
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Java Server Pages
Jsp sasidhar
JSP diana y yo
JSP AND XML USING JAVA WITH GET AND POST METHODS
Jsp servlets
Jsp element
Introduction - Java Server Programming (JSP)
C:\fakepath\jsp01
JSP.pptx
JSP- JAVA SERVER PAGES
Introduction to JSP pages
21CS642 Module 4_2 JSP PPT.pptx VI SEM CSE
J2EE - JSP-Servlet- Container - Components
Advance java session 10
Module 3.pptx.............................
Introduction to JSP
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ad

More from Hansi Thenuwara (13)

PPTX
Natural language processing
PPTX
Travel sri lanka
PPTX
Mobile based electricity
PPTX
Case study3
PPTX
Scrum methodology
PPTX
ICT boom in India
PDF
New dimensions of technology
PPTX
Cleaner production
PPTX
Tourism industry in Sri Lanka
PPTX
Operations Management Study in Textured Jersy Lanka Limited
PPTX
UML Class Diagram G-3-122139
DOCX
Patient management
PPTX
Channelling Management System
Natural language processing
Travel sri lanka
Mobile based electricity
Case study3
Scrum methodology
ICT boom in India
New dimensions of technology
Cleaner production
Tourism industry in Sri Lanka
Operations Management Study in Textured Jersy Lanka Limited
UML Class Diagram G-3-122139
Patient management
Channelling Management System

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MIND Revenue Release Quarter 2 2025 Press Release
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
Understanding_Digital_Forensics_Presentation.pptx
Electronic commerce courselecture one. Pdf
Unlocking AI with Model Context Protocol (MCP)

Jsp & struts

  • 2. JSP -Java Server Pages The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little HTML mixed in JSP is an alternate way of creating servlets  JSP is written as ordinary HTML, with a little Java mixed in  The Java is enclosed in special tags .  The HTML is known as the template text JSP files must have the extension .jsp 2
  • 3. JSP scripting elements There is more than one type of JSP “tag” depending on what you want done with the Java <%= expression %>  The expression is evaluated and the result is inserted into the HTML page <% code %>  The code is inserted into the servlet's service method  This construction is called a scriptlet  <%! declarations %>  The declarations are inserted into the servlet class, not into a method 3
  • 4. 4 Example JSP <HTML> <BODY> Hello! The time is now <%= new java.util.Date() %> </BODY> </HTML> Notes:  The <%= ... %> tag is used, because we are computing a value and inserting it into the HTML  The fully qualified name (java.util.Date) is used, instead of the short name (Date).
  • 5. Variables You can declare your own variables, as usual JSP provides several predefined variables  request : The HttpServletRequest parameter  response : The HttpServletResponse parameter  session : The HttpSession associated with the request, or null if there is none  out : A JspWriter (like a PrintWriter) used to send output to the client Example:  Your hostname: <%= request.getRemoteHost() %> 5
  • 6. Scriptlets Scriptlets are enclosed in <% ... %> tags  Scriptlets do not produce a value that is inserted directly into the HTML (as is done with <%= ... %>)  Scriptlets are Java code that may write into the HTML  Example: <% String queryData = request.getQueryString(); out.println("Attached GET data: " + queryData); %> Scriptlets are inserted into the servlet exactly as written, and are not compiled until the entire servlet is compiled 6
  • 7. Declarations Use <%! ... %> for declarations to be added to servlet class, not to any particular method  Servlets are multithreaded, so nonlocal variables must be handled with extreme care  If declared with <% ... %>, variables are local and OK  Data can also safely be put in the request or session objects Example: <%! private int accessCount = 0; %> Accesses to page since server reboot: <%= ++accessCount %> Use <%! ... %> to declare methods as easily as to declare variables 7
  • 8. JSP in XML JSP can be embedded in XML as well as in HTML Due to XML’s syntax rules, the tags must be different (but they do the same things) HTML: <%= expression %> XML: <jsp:expression>expression</jsp:expression> HTML: <% code %> XML: <jsp:scriptlet>code</jsp:scriptlet> HTML: <%! declarations %> XML: <jsp:declaration>declarations</jsp:declaration> HTML: <%@ include file=URL %> XML: <jsp:directive.include file="URL"/> 8
  • 9. Struts  Struts is an open-source framework for building more flexible, maintainable and structured front-ends in Java web applications  There are two key components in a web application: the data and business logic performed on this data the presentation of data  Struts helps structuring these components in a Java web app. controls the flow of the web application, strictly separating these components unifies the interaction between them 9
  • 10. Why struts are useful structural separation of data presentation and business logic Struts provides a Controller that manages the control flow easy localization based on standard Java technologies open-source 10