SlideShare a Scribd company logo
1 of 26
Server-side  Web Programming Lecture 5:  Java Servlets and the  Control-View Architecture
The Control-View Architecture ,[object Object],[object Object],[object Object],[object Object]
The Control-View Architecture ,[object Object],[object Object],[object Object],[object Object],[object Object]
Java Servlets ,[object Object],[object Object],[object Object],[object Object],Tomcat Request for  servlet Servlet Servlet methods called JSP Redirect to appropriate response page html JSP converted to html Response
The Control-View Architecture ,[object Object],[object Object],[object Object],[object Object],request Control servlet JSP response JSPs  act  as  views JSP JSP
Adding a Servlet ,[object Object],Choose Servlet type
Adding a Servlet Give it a name
Adding a Servlet Adds servlet information to  web.xml  descriptor file. This allows other servlets and JSPs to refer to it using its  name .
Adding a Servlet ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Basic Servlet Structure ,[object Object],[object Object],[object Object],[object Object],[object Object]
Basic Servlet Structure ,[object Object],[object Object],[object Object]
Importing Servlet Libraries ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Invoking a Servlet from a JSP ,[object Object]
Servlet Background ,[object Object],[object Object],[object Object],[object Object],[object Object]
Servlet Background ,[object Object],[object Object],[object Object],[object Object],[object Object],Only this done in subsequent requests Much more efficient than running JSP again each request
Servlet Redirection ,[object Object],[object Object],dispatcherObject   is a new object that holds information about the redirection Forward control to this JSP on the same site The / tells Tomcat to look in the application root directory Get the location of the site (so can do a relative url forward)
Servlet Redirection ,[object Object],[object Object],Transfer control using the  dispatcherObject Both the request and response must be passed so the JSP has access to parameters, etc.
Redirection Example ,[object Object],[object Object],[object Object],[object Object],Validate.java servlet
Redirection Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Passing Information to the JSP ,[object Object],[object Object],[object Object],[object Object],servlet Request parameter=value parameter=value … JSP Request parameter=value parameter=value attribute=value …
Passing Information to the JSP ,[object Object],[object Object],Since attribute can be  any  type, must use casting to tell Java original type
Passing Information to the JSP Code in servlet to pass price per unit and total cost as strings
Passing Information to the JSP Code in JSP to retrieve price per unit and total cost as strings
Servlet Details ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Servlet Details ,[object Object],[object Object],[object Object],[object Object],WidgetSite Validate request Validation servlet Error JSP response JSP for standard configuration JSP for custom configuration Servlet to choose computer type
Servlet Details ,[object Object],[object Object],[object Object]

More Related Content

What's hot

Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
vikram singh
 
Core web application development
Core web application developmentCore web application development
Core web application development
Bahaa Farouk
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
vikram singh
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
vikram singh
 

What's hot (20)

Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Jsp servlets
Jsp servletsJsp servlets
Jsp servlets
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
Core web application development
Core web application developmentCore web application development
Core web application development
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Servlets
ServletsServlets
Servlets
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Servlet
Servlet Servlet
Servlet
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Servlets
ServletsServlets
Servlets
 
Java server pages
Java server pagesJava server pages
Java server pages
 
JDBC
JDBCJDBC
JDBC
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 

Similar to Lecture5

Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
Geethu Mohan
 
Csajsp Chapter15
Csajsp Chapter15Csajsp Chapter15
Csajsp Chapter15
Adil Jafri
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
rvpprash
 

Similar to Lecture5 (20)

Servlet11
Servlet11Servlet11
Servlet11
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Java servlets
Java servletsJava servlets
Java servlets
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
Csajsp Chapter15
Csajsp Chapter15Csajsp Chapter15
Csajsp Chapter15
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
 
E-MARKETING E-ZONE PPT Using ADVANCED JAVA
E-MARKETING E-ZONE PPT Using ADVANCED JAVAE-MARKETING E-ZONE PPT Using ADVANCED JAVA
E-MARKETING E-ZONE PPT Using ADVANCED JAVA
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
Servlets
ServletsServlets
Servlets
 

More from Châu Thanh Chương (20)

Lecture19
Lecture19Lecture19
Lecture19
 
Lecture18
Lecture18Lecture18
Lecture18
 
Lecture17
Lecture17Lecture17
Lecture17
 
Lecture16
Lecture16Lecture16
Lecture16
 
Lecture15
Lecture15Lecture15
Lecture15
 
Lecture14
Lecture14Lecture14
Lecture14
 
Lecture13
Lecture13Lecture13
Lecture13
 
Lecture12
Lecture12Lecture12
Lecture12
 
Lecture11
Lecture11Lecture11
Lecture11
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture9
Lecture9Lecture9
Lecture9
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7 pattern
Lecture7 patternLecture7 pattern
Lecture7 pattern
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture2
Lecture2Lecture2
Lecture2
 
Lecture1
Lecture1Lecture1
Lecture1
 
Lecture19
Lecture19Lecture19
Lecture19
 
7 data management design
7 data management design7 data management design
7 data management design
 

Recently uploaded

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Lecture5

  • 1. Server-side Web Programming Lecture 5: Java Servlets and the Control-View Architecture
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Adding a Servlet Give it a name
  • 8. Adding a Servlet Adds servlet information to web.xml descriptor file. This allows other servlets and JSPs to refer to it using its name .
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Passing Information to the JSP Code in servlet to pass price per unit and total cost as strings
  • 23. Passing Information to the JSP Code in JSP to retrieve price per unit and total cost as strings
  • 24.
  • 25.
  • 26.