SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
JSP

    Cornelius Koo, ST
       JavaSchool
          2005
Jl. Cemara 2/20, Salatiga
Accessing Class via JSP
<html>
<body>
The page count is :
<%
  out.println(foo.Counter.getCount());
%>
</body>
</html>
package foo;

public class Counter {
  private static int count;
  public static synchronized int getCount() {
      count++;
      return count;
  }
}
Importing Class Using
   Page Directives
<%@ page import=“foo.*” %>
<html>
<body>
The page count is :
<%
  out.println(Counter.getCount());
%>
</body>
</html>
<%@ page import=“foo.*, java.util.*,
 java.sql.*” %>
Scriptlet
<%@ page import=“foo.*” %>
<html>
<body>
The page count is :
<%
  out.println(Counter.getCount());
%>
</body>
</html>
Expression
<%@ page import=“foo.*” %>
<html>
<body>
The page count is :
<%= Counter.getCount() %>
</body>
</html>
out.print( Counter.getCount() );
• Scriptlet  <% ... %>
• Directive  <%@ … %>
• Expression <%= … %>
Declaring Variables and
       Methods
Inside The Service Method
<html>
<body>
<% int count = 0; %>
The page count is :
<%= ++count %>
</body>
</html>
Public class basicCounter_jsp extends HttpServlet {
  public void _jspService(
       HttpServletRequest req,
       HttpServletResponse res) throws
       java.io.IOException {
              PrintWriter out = response.getWriter();
              response.setContentType(“text/html”);
              out.write(“<html><body>”);
              int count = 0;
              out.write(“The page count is :”);
              out.write( ++count );
              out.write(“</body></html>”);
  }
}
Inside The Servlet Scope
<html>
<body>
<%! int count = 0; %>
The page count is :
<%= ++count %>
</body>
</html>
Public class basicCounter_jsp extends HttpServlet {
  int count = 0;
  public void _jspService(
       HttpServletRequest req,
       HttpServletResponse res) throws
       java.io.IOException {
              PrintWriter out = response.getWriter();
              response.setContentType(“text/html”);
              out.write(“<html><body>”);
              out.write(“The page count is :”);
              out.write( ++count );
              out.write(“</body></html>”);
  }
}
Implicit Objects
•   JspWriter             -   out
•   HttpServletRequest    -   request
•   HttpServletResponse   -   response
•   HttpSession           -   session
•   ServletContext        -   application
•   ServletConfig         -   config
•   JSPException          -   exception
•   PageContext           -   pageContext
•   Object                -   page
Comment
• <!-- HTML Comments -->
• <%-- JSP Comments --%>
The Compilation Process
Init Param
DD
<web-app>
  ...
  <servlet>
      <servlet-name>TestInitServlet</servlet-name>
      <jsp-file>/init.jsp</jsp-file>
      <init-param>
              <param-name>name</param-name>
              <param-value>zaradaz</param-value>
      </init-param>
  </servlet>
  ...
</web-app>
Overriding jspInit()
<%!
  public void jspInit() {

       ServletConfig servletConfig = getServletConfig();

       String name = servletConfig.getInitParameter("name");


       ServletContext ctx = getServletContext();
       ctx.setAttribute("name", name);
 }
%>
Attributes in JSP
PageContext
Page Scoped Attribute
Set
<% Double index = new Double(45.4); %>
<% pageContext.setAttribute( "attr" , index); %>

Get
<%= pageContext.getAttribute( "attr") %>
Request Scoped Attribute
Set
<% Double index = new Double(45.4); %>
<% pageContext.setAttribute( "attr" , index,
 PageContext.REQUEST_ATTRIBUTE); %>

Get
<%= pageContext.getAttribute( "attr" ,
 PageContext.REQUEST_ATTRIBUTE) %>
Session Scoped Attribute
Set
<% Double index = new Double(45.4); %>
<% pageContext.setAttribute( "attr" , index,
 PageContext.SESSION_ATTRIBUTE); %>

Get
<%= pageContext.getAttribute( "attr" ,
 PageContext.SESSION_ATTRIBUTE) %>
Application Scoped Attribute
Set
<% Double index = new Double(45.4); %>
<% pageContext.setAttribute( "attr" , index,
 PageContext.APPLICATION_ATTRIBUTE); %>

Get
<%= pageContext.getAttribute( "attr" ,
 PageContext.APPLICATION_ATTRIBUTE) %>
Finding Attributes
<%= pageContext.findAttribute( "attr" ) %>

Priority :
1. Request
2. Session
3. Application
Directives
Page Directive
<%@ page import=“foo.*, java.util.*,
 java.sql.*”%>
Taglib Directive
<%@ taglib tagdir=“/WEB-INF/tags/zip”
 prefix=“zip” %>
Include Directive
<%@ include file=“page.html” %>
Blocking Java Code
• We can block the use of scriptlet,
  expression and declarations in our jsp
  code.
<web-app>
...
    <jsp-config>
         <jsp-property-group>
                <url-pattern>*.jsp</url-pattern>
                <scripting-invalid>true</scripting-invalid>
         </jsp-property-group>
    </jsp-config>
...
</web-app>
Actions
<jsp:include … />
• <@ include … > insertion happens at
  translation time

• <jsp:include … /> insertion happens at
  runtime
Include Directive
<body>
<%@ include file="header.jspf" %>

 <h3>The main body</h3>

<%@ include file="footer.jspf" %>
</body>
Include Directive
• header.jspf
<h1>This is the Header</h1>

• footer.jspf
<b><i>JavaSchool, school of object
  technology</i></b><br>
<address> Jl. Cemara 2/20, Salatiga
  </address>
Include Actions
<jsp:include page="header.jspf" flush="true"/>

<jsp:include page="action_header.jsp" flush="true">
   <jsp:param name="title" value="This is the header's title"/>
</jsp:include>
<jsp:forward … />
<body>
  Please login first, and don't forget to enter your
  name <br>
  <form name="form1" method="post"
  action="hello.jsp">
   <input type="text" name="userName">
   <input type="submit" name="Submit"
  value="Submit">
  </form>
</body>                                     login.jsp
<body>
  <% if (request.getParameter("userName") ==
  null ||
  request.getParameter("userName").equals("")) {
      %>
      <jsp:forward page="login.jsp"/>
  <% } %>

  Hello ${param.userName}
</body>                                hello.jsp
<jsp:useBean … />
<jsp:useBean
  id="person"
  class="jsp.example.bean.Person"
  scope="request"/>
Person is : <jsp:getProperty name="person" property="name"/> <br/>
Address : <jsp:getProperty name="person" property="address"/> <br/>
Gender : <jsp:getProperty name="person" property="gender"/> <br/>
Age      : <jsp:getProperty name="person" property="age"/> <br/>
<jsp:getProperty … />
<jsp:useBean
   id="person"
   class="jsp.example.bean.Person"
   scope="request"/>

Person is :

<jsp:getProperty
  name="person"
  property="name"/>
<br/>
Address : <jsp:getProperty name="person" property="address"/> <br/>
Gender : <jsp:getProperty name="person" property="gender"/> <br/>
Age     : <jsp:getProperty name="person" property="age"/> <br/>
<jsp:setProperty … />
<jsp:setProperty
  name="person"
  property="name"
  value="John" />
Creating Bean
Use <jsp:useBean>
<jsp:useBean
   id=“person”
   class="jsp.example.bean.Person"
   scope=“page“ >

 <jsp:setProperty
  name="person"
  property="name"
  value="John" />

</jsp:useBean>
• The bean is created only when there’s no
  bean object at all.
Shorter Way
<jsp:useBean id="person"
  class="jsp.example.bean.Person"
  scope="request">
 <jsp:setProperty
 name="person" property="*"/>
</jsp:useBean>
Pre-Condition
Pre-Condition
<td><input type="text" name="name"></td>

<td><input type="text" name="address"></td>

<td><input type="radio" name="gender"
  value="true">Male</td>
<td><input type="radio" name="gender"
  value="false">Female</td>

<td><input type="text" name="age"></td>
Inherited Bean
Usage
<jsp:useBean id="person"
   type="jsp.example.bean.Person"
   class="jsp.example.bean.Employee"
    scope="request">
    <jsp:setProperty name="person" property="*"/>
</jsp:useBean>

Person : <jsp:getProperty name="person" property="name"/> <br/>
Address : <jsp:getProperty name="person" property="address"/><br/>
Gender : <jsp:getProperty name="person" property="gender"/> <br/>
Age     : <jsp:getProperty name="person" property="age"/> <br/>
Emp ID : <jsp:getProperty name="person" property="empID"/> <br/>
• Person person = new Employee();
  type                class
<jsp:plugin>
<jsp:params>
<jsp:param>
<jsp:fallback>
<jsp:plugin type="applet"
  code="jsp.example.TestApplet"
  codebase="/classes/applets" height="100"
  width="100">
  <jsp:params>
      <jsp:param name="color" value="black"/>
      <jsp:param name="speed" value="fast"/>
      <jsp:param name="sound" value="off"/>
  </jsp:params>
  <jsp:fallback>Your browser cannot display
  the applet</jsp:fallback>
</jsp:plugin>

Contenu connexe

Tendances

JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in muleAnilKumar Etagowni
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance JavaDarshit Metaliya
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final) Hitesh-Java
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Serhii Kartashov
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB IntegrationAnilKumar Etagowni
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Som Prakash Rai
 
Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Clarence Ngoh
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 

Tendances (20)

Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in mule
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Jsp
JspJsp
Jsp
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final)
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
 
Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 

En vedette

En vedette (7)

Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Losseless
LosselessLosseless
Losseless
 
Video Streaming - 4.ppt
Video Streaming - 4.pptVideo Streaming - 4.ppt
Video Streaming - 4.ppt
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Compression
CompressionCompression
Compression
 

Similaire à JSP

JavaServer Pages
JavaServer Pages JavaServer Pages
JavaServer Pages profbnk
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkara JUG
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauSpiffy
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceNiraj Bharambe
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4DEVCON
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneRafael Felix da Silva
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012cagataycivici
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortalJennifer Bourey
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 

Similaire à JSP (20)

JavaServer Pages
JavaServer Pages JavaServer Pages
JavaServer Pages
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 
Html To JSP
Html To JSPHtml To JSP
Html To JSP
 
Jsp Notes
Jsp NotesJsp Notes
Jsp Notes
 
Presentation
PresentationPresentation
Presentation
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer science
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
jQuery
jQueryjQuery
jQuery
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
Struts Overview
Struts OverviewStruts Overview
Struts Overview
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012
 
Jsf
JsfJsf
Jsf
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 

Plus de corneliuskoo

Expression Language in JSP
Expression Language in JSPExpression Language in JSP
Expression Language in JSPcorneliuskoo
 
13 Low Level UI Event Handling
13 Low Level UI Event Handling13 Low Level UI Event Handling
13 Low Level UI Event Handlingcorneliuskoo
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handlingcorneliuskoo
 
07 Midlet On The Web
07 Midlet On The Web07 Midlet On The Web
07 Midlet On The Webcorneliuskoo
 
05 J2ME Wtk Command Line
05 J2ME Wtk Command Line05 J2ME Wtk Command Line
05 J2ME Wtk Command Linecorneliuskoo
 
04 J2ME Wireless Tool Kit
04 J2ME Wireless Tool Kit04 J2ME Wireless Tool Kit
04 J2ME Wireless Tool Kitcorneliuskoo
 
02a cldc property support
02a cldc property support02a cldc property support
02a cldc property supportcorneliuskoo
 
01 java 2 micro edition
01 java 2 micro edition01 java 2 micro edition
01 java 2 micro editioncorneliuskoo
 

Plus de corneliuskoo (15)

Basic JSTL
Basic JSTLBasic JSTL
Basic JSTL
 
Expression Language in JSP
Expression Language in JSPExpression Language in JSP
Expression Language in JSP
 
Html Hands On
Html Hands OnHtml Hands On
Html Hands On
 
13 Low Level UI Event Handling
13 Low Level UI Event Handling13 Low Level UI Event Handling
13 Low Level UI Event Handling
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
 
09 Display
09 Display09 Display
09 Display
 
08 Midlet Basic
08 Midlet Basic08 Midlet Basic
08 Midlet Basic
 
07 Midlet On The Web
07 Midlet On The Web07 Midlet On The Web
07 Midlet On The Web
 
06 Eclipse ME
06 Eclipse ME06 Eclipse ME
06 Eclipse ME
 
05 J2ME Wtk Command Line
05 J2ME Wtk Command Line05 J2ME Wtk Command Line
05 J2ME Wtk Command Line
 
04 J2ME Wireless Tool Kit
04 J2ME Wireless Tool Kit04 J2ME Wireless Tool Kit
04 J2ME Wireless Tool Kit
 
03 midp
03 midp03 midp
03 midp
 
02a cldc property support
02a cldc property support02a cldc property support
02a cldc property support
 
02 cldc
02 cldc02 cldc
02 cldc
 
01 java 2 micro edition
01 java 2 micro edition01 java 2 micro edition
01 java 2 micro edition
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

JSP

  • 1. JSP Cornelius Koo, ST JavaSchool 2005 Jl. Cemara 2/20, Salatiga
  • 3. <html> <body> The page count is : <% out.println(foo.Counter.getCount()); %> </body> </html>
  • 4. package foo; public class Counter { private static int count; public static synchronized int getCount() { count++; return count; } }
  • 5. Importing Class Using Page Directives
  • 6. <%@ page import=“foo.*” %> <html> <body> The page count is : <% out.println(Counter.getCount()); %> </body> </html>
  • 7. <%@ page import=“foo.*, java.util.*, java.sql.*” %>
  • 9. <%@ page import=“foo.*” %> <html> <body> The page count is : <% out.println(Counter.getCount()); %> </body> </html>
  • 11. <%@ page import=“foo.*” %> <html> <body> The page count is : <%= Counter.getCount() %> </body> </html>
  • 13. • Scriptlet <% ... %> • Directive <%@ … %> • Expression <%= … %>
  • 15. Inside The Service Method <html> <body> <% int count = 0; %> The page count is : <%= ++count %> </body> </html>
  • 16. Public class basicCounter_jsp extends HttpServlet { public void _jspService( HttpServletRequest req, HttpServletResponse res) throws java.io.IOException { PrintWriter out = response.getWriter(); response.setContentType(“text/html”); out.write(“<html><body>”); int count = 0; out.write(“The page count is :”); out.write( ++count ); out.write(“</body></html>”); } }
  • 17. Inside The Servlet Scope <html> <body> <%! int count = 0; %> The page count is : <%= ++count %> </body> </html>
  • 18. Public class basicCounter_jsp extends HttpServlet { int count = 0; public void _jspService( HttpServletRequest req, HttpServletResponse res) throws java.io.IOException { PrintWriter out = response.getWriter(); response.setContentType(“text/html”); out.write(“<html><body>”); out.write(“The page count is :”); out.write( ++count ); out.write(“</body></html>”); } }
  • 20. JspWriter - out • HttpServletRequest - request • HttpServletResponse - response • HttpSession - session • ServletContext - application • ServletConfig - config • JSPException - exception • PageContext - pageContext • Object - page
  • 22. • <!-- HTML Comments --> • <%-- JSP Comments --%>
  • 24.
  • 26. DD <web-app> ... <servlet> <servlet-name>TestInitServlet</servlet-name> <jsp-file>/init.jsp</jsp-file> <init-param> <param-name>name</param-name> <param-value>zaradaz</param-value> </init-param> </servlet> ... </web-app>
  • 27. Overriding jspInit() <%! public void jspInit() { ServletConfig servletConfig = getServletConfig(); String name = servletConfig.getInitParameter("name"); ServletContext ctx = getServletContext(); ctx.setAttribute("name", name); } %>
  • 30.
  • 31. Page Scoped Attribute Set <% Double index = new Double(45.4); %> <% pageContext.setAttribute( "attr" , index); %> Get <%= pageContext.getAttribute( "attr") %>
  • 32. Request Scoped Attribute Set <% Double index = new Double(45.4); %> <% pageContext.setAttribute( "attr" , index, PageContext.REQUEST_ATTRIBUTE); %> Get <%= pageContext.getAttribute( "attr" , PageContext.REQUEST_ATTRIBUTE) %>
  • 33. Session Scoped Attribute Set <% Double index = new Double(45.4); %> <% pageContext.setAttribute( "attr" , index, PageContext.SESSION_ATTRIBUTE); %> Get <%= pageContext.getAttribute( "attr" , PageContext.SESSION_ATTRIBUTE) %>
  • 34. Application Scoped Attribute Set <% Double index = new Double(45.4); %> <% pageContext.setAttribute( "attr" , index, PageContext.APPLICATION_ATTRIBUTE); %> Get <%= pageContext.getAttribute( "attr" , PageContext.APPLICATION_ATTRIBUTE) %>
  • 35. Finding Attributes <%= pageContext.findAttribute( "attr" ) %> Priority : 1. Request 2. Session 3. Application
  • 37. Page Directive <%@ page import=“foo.*, java.util.*, java.sql.*”%>
  • 38. Taglib Directive <%@ taglib tagdir=“/WEB-INF/tags/zip” prefix=“zip” %>
  • 39. Include Directive <%@ include file=“page.html” %>
  • 41. • We can block the use of scriptlet, expression and declarations in our jsp code.
  • 42. <web-app> ... <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</scripting-invalid> </jsp-property-group> </jsp-config> ... </web-app>
  • 45. • <@ include … > insertion happens at translation time • <jsp:include … /> insertion happens at runtime
  • 46. Include Directive <body> <%@ include file="header.jspf" %> <h3>The main body</h3> <%@ include file="footer.jspf" %> </body>
  • 47. Include Directive • header.jspf <h1>This is the Header</h1> • footer.jspf <b><i>JavaSchool, school of object technology</i></b><br> <address> Jl. Cemara 2/20, Salatiga </address>
  • 48. Include Actions <jsp:include page="header.jspf" flush="true"/> <jsp:include page="action_header.jsp" flush="true"> <jsp:param name="title" value="This is the header's title"/> </jsp:include>
  • 50. <body> Please login first, and don't forget to enter your name <br> <form name="form1" method="post" action="hello.jsp"> <input type="text" name="userName"> <input type="submit" name="Submit" value="Submit"> </form> </body> login.jsp
  • 51. <body> <% if (request.getParameter("userName") == null || request.getParameter("userName").equals("")) { %> <jsp:forward page="login.jsp"/> <% } %> Hello ${param.userName} </body> hello.jsp
  • 53. <jsp:useBean id="person" class="jsp.example.bean.Person" scope="request"/> Person is : <jsp:getProperty name="person" property="name"/> <br/> Address : <jsp:getProperty name="person" property="address"/> <br/> Gender : <jsp:getProperty name="person" property="gender"/> <br/> Age : <jsp:getProperty name="person" property="age"/> <br/>
  • 55. <jsp:useBean id="person" class="jsp.example.bean.Person" scope="request"/> Person is : <jsp:getProperty name="person" property="name"/> <br/> Address : <jsp:getProperty name="person" property="address"/> <br/> Gender : <jsp:getProperty name="person" property="gender"/> <br/> Age : <jsp:getProperty name="person" property="age"/> <br/>
  • 57. <jsp:setProperty name="person" property="name" value="John" />
  • 59. Use <jsp:useBean> <jsp:useBean id=“person” class="jsp.example.bean.Person" scope=“page“ > <jsp:setProperty name="person" property="name" value="John" /> </jsp:useBean>
  • 60. • The bean is created only when there’s no bean object at all.
  • 62. <jsp:useBean id="person" class="jsp.example.bean.Person" scope="request"> <jsp:setProperty name="person" property="*"/> </jsp:useBean>
  • 64. Pre-Condition <td><input type="text" name="name"></td> <td><input type="text" name="address"></td> <td><input type="radio" name="gender" value="true">Male</td> <td><input type="radio" name="gender" value="false">Female</td> <td><input type="text" name="age"></td>
  • 66.
  • 67. Usage <jsp:useBean id="person" type="jsp.example.bean.Person" class="jsp.example.bean.Employee" scope="request"> <jsp:setProperty name="person" property="*"/> </jsp:useBean> Person : <jsp:getProperty name="person" property="name"/> <br/> Address : <jsp:getProperty name="person" property="address"/><br/> Gender : <jsp:getProperty name="person" property="gender"/> <br/> Age : <jsp:getProperty name="person" property="age"/> <br/> Emp ID : <jsp:getProperty name="person" property="empID"/> <br/>
  • 68. • Person person = new Employee(); type class
  • 70. <jsp:plugin type="applet" code="jsp.example.TestApplet" codebase="/classes/applets" height="100" width="100"> <jsp:params> <jsp:param name="color" value="black"/> <jsp:param name="speed" value="fast"/> <jsp:param name="sound" value="off"/> </jsp:params> <jsp:fallback>Your browser cannot display the applet</jsp:fallback> </jsp:plugin>