SlideShare a Scribd company logo
Server-side  Web Programming Lecture 6:  Java Servlets and the  web.xml  Configuration File
Configuration Files Each webapp has a  web.xml  file In  WEB-INF  subdirectory Defines: Mapping from servlet names to servlet files  Global constants Default error pages Security roles…
The  web.xml  file Complex (and finicky) XML If buggy, application  will not load Errors displayed in Tomcat window when started NetBeans provides interface to manipulate its values
The  web.xml  file Internally, still XML Can view and edit at XML tab Basic form of XML: <tag>text</tag> or <tag/> Tags must be properly balanced and nested Must have a root tag  <webapp>
Welcome Page Properties Page shown at webapp startup Default: index.jsp Can change to a new welcome file
New Welcome Page Will go to that page when webapp started Note change in web.xml
Servlet Mapping Web.xml links  referrer page  to be linked with  actual servlet class Mapping from a  name  to a  java class Allows servlet code to be changed without having to rewrite other pages Important since name of class = name of file in Java Mapping from a  url pattern  to a  servlet name Allows servlets to be “hidden” from user Referring file that invokes servlet url pattern used  in FORM ACTION web.xml url pattern    name name    servlet class Java servlet class with actual code
Servlet Mapping No such file – this is just a url pattern that will refer to an actual servlet via web.xml Added to the url patterns that map to this servlet
Servlet Mapping Note that the url pattern appears in the browser Code in web.xml that does the servlet mapping
Initial Parameters Global constants  stored in web.xml Better than “hardwiring” values directly into the code Easier for  nonprogrammer  to modify Form like parameter: name/value Example: “price per unit” in widget site Note that such information is usually in a database However, the name of the database is often an initial parameter! web.xml pricePerUnit=9.95 Java servlet class that needs widget cost
Initial Parameters Configuration level Specific to  single  servlet Context level General to  all  server pages/servlets overall application context … context-level parameters SomeServlet ‘s configuration configuration-level parameters SomeServlet  object AnotherServlet ‘s configuration configuration-level parameters AnothereServlet  object
Configuration Parameters Can create in servlet tab
Configuration Parameters Form of xml tag
Configuration Parameters Accessing from servlet: Get the  servlet configuration ServletConfig config = getServletConfig(); Get the value corresponding to the name of the parameter String  value  = config.getInitParameter(“ name &quot;);
Context Parameters Can create in general tab
Context Parameters Form of xml tag
Configuration Parameters Accessing from servlet: Get the  servlet configuration ServletConfig config = getServletConfig(); Get the  webapp context  from the configuration ServletContext context = config.getServletContext(); Get the value corresponding to the name of the parameter String  value  = context.getInitParameter(“ name &quot;);   Accessing from a JSP: String  value  = application.getInitParameter(“ name &quot;); Built-in object in JSP  (like “request”)
Configuration Parameters

More Related Content

PPTX
mule salesforce
 
PPTX
Web api
PPTX
Mule using Salesforce
PPTX
Mule with salesforce push topic notification copy
PPTX
Data weave in Mule
KEY
CakePHP REST Plugin
PPTX
Mule
mule salesforce
 
Web api
Mule using Salesforce
Mule with salesforce push topic notification copy
Data weave in Mule
CakePHP REST Plugin
Mule

What's hot (19)

PPTX
Maven tools & archetypes
PPTX
Mule data bases
PDF
Apikit in studio
PPTX
Mule esb soap_service
PPTX
ASP.NET Page Life Cycle
PPTX
CakeFest 2013 - A-Z REST APIs
PPT
Introduction To Asp.Net Ajax
PPTX
Ajax control asp.net
PPTX
Deploying and running mule standalone
PPTX
Mulesoft salesforce connector to update Object.
PPTX
Deploying and Running in Mule
ODP
Example mule
PPT
ASP.NET AJAX Basics
PPTX
Stored procedure in Mule
PDF
Spring tutorial
PPTX
Automatic documentation with mule
 
PPTX
Mulesoft Calling Flow of Other Applications
PDF
Some tips to improve developer experience with Symfony
PPTX
Web application with mule
Maven tools & archetypes
Mule data bases
Apikit in studio
Mule esb soap_service
ASP.NET Page Life Cycle
CakeFest 2013 - A-Z REST APIs
Introduction To Asp.Net Ajax
Ajax control asp.net
Deploying and running mule standalone
Mulesoft salesforce connector to update Object.
Deploying and Running in Mule
Example mule
ASP.NET AJAX Basics
Stored procedure in Mule
Spring tutorial
Automatic documentation with mule
 
Mulesoft Calling Flow of Other Applications
Some tips to improve developer experience with Symfony
Web application with mule
Ad

Viewers also liked (9)

PDF
Bai 09 Basic jsp
PPT
Struts2 in a nutshell
PDF
Web Development with Apache Struts 2
PPT
Struts2.x
PPTX
Apache Struts 2 Framework
PPT
Introducing Struts 2
PPTX
PDF
Struts2
PDF
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Bai 09 Basic jsp
Struts2 in a nutshell
Web Development with Apache Struts 2
Struts2.x
Apache Struts 2 Framework
Introducing Struts 2
Struts2
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Ad

Similar to Lecture6 (20)

PDF
ServletConfig & ServletContext
PPT
Web Application Deployment
PDF
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 5...
PPT
Web Applications and Deployment
DOC
Sel study notes
PPTX
Introduction to JSP
PPT
J2EE - JSP-Servlet- Container - Components
PPT
Web Deployment With Visual Studio 2010
DOCX
Html servlet example
ODP
Spring Portlet MVC
PPTX
Spring MVC
PPTX
Jsp and jstl
PPT
Knowledge Sharing : Java Servlet
PPT
Introduction to the Servlet / JSP course
PPTX
SERVLETS (2).pptxintroduction to servlet with all servlets
PPTX
Entity framework and how to use it
DOC
Unit5 servlets
KEY
Integrating Wicket with Java EE 6
PDF
Spring mvc 2.0
ServletConfig & ServletContext
Web Application Deployment
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 5...
Web Applications and Deployment
Sel study notes
Introduction to JSP
J2EE - JSP-Servlet- Container - Components
Web Deployment With Visual Studio 2010
Html servlet example
Spring Portlet MVC
Spring MVC
Jsp and jstl
Knowledge Sharing : Java Servlet
Introduction to the Servlet / JSP course
SERVLETS (2).pptxintroduction to servlet with all servlets
Entity framework and how to use it
Unit5 servlets
Integrating Wicket with Java EE 6
Spring mvc 2.0

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

PPT
PPT
PPT
PPT
PPT
PPT
PPT
PPT
PPT
PPT
PPT
Lecture7 pattern
PPT
PPT
7 data management design
PPT
6 class design

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Modernizing your data center with Dell and AMD
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
A Presentation on Artificial Intelligence
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Monthly Chronicles - July 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Modernizing your data center with Dell and AMD
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
The Rise and Fall of 3GPP – Time for a Sabbatical?
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
A Presentation on Artificial Intelligence
Digital-Transformation-Roadmap-for-Companies.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Understanding_Digital_Forensics_Presentation.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.

Lecture6

  • 1. Server-side Web Programming Lecture 6: Java Servlets and the web.xml Configuration File
  • 2. Configuration Files Each webapp has a web.xml file In WEB-INF subdirectory Defines: Mapping from servlet names to servlet files Global constants Default error pages Security roles…
  • 3. The web.xml file Complex (and finicky) XML If buggy, application will not load Errors displayed in Tomcat window when started NetBeans provides interface to manipulate its values
  • 4. The web.xml file Internally, still XML Can view and edit at XML tab Basic form of XML: <tag>text</tag> or <tag/> Tags must be properly balanced and nested Must have a root tag <webapp>
  • 5. Welcome Page Properties Page shown at webapp startup Default: index.jsp Can change to a new welcome file
  • 6. New Welcome Page Will go to that page when webapp started Note change in web.xml
  • 7. Servlet Mapping Web.xml links referrer page to be linked with actual servlet class Mapping from a name to a java class Allows servlet code to be changed without having to rewrite other pages Important since name of class = name of file in Java Mapping from a url pattern to a servlet name Allows servlets to be “hidden” from user Referring file that invokes servlet url pattern used in FORM ACTION web.xml url pattern  name name  servlet class Java servlet class with actual code
  • 8. Servlet Mapping No such file – this is just a url pattern that will refer to an actual servlet via web.xml Added to the url patterns that map to this servlet
  • 9. Servlet Mapping Note that the url pattern appears in the browser Code in web.xml that does the servlet mapping
  • 10. Initial Parameters Global constants stored in web.xml Better than “hardwiring” values directly into the code Easier for nonprogrammer to modify Form like parameter: name/value Example: “price per unit” in widget site Note that such information is usually in a database However, the name of the database is often an initial parameter! web.xml pricePerUnit=9.95 Java servlet class that needs widget cost
  • 11. Initial Parameters Configuration level Specific to single servlet Context level General to all server pages/servlets overall application context … context-level parameters SomeServlet ‘s configuration configuration-level parameters SomeServlet object AnotherServlet ‘s configuration configuration-level parameters AnothereServlet object
  • 12. Configuration Parameters Can create in servlet tab
  • 14. Configuration Parameters Accessing from servlet: Get the servlet configuration ServletConfig config = getServletConfig(); Get the value corresponding to the name of the parameter String value = config.getInitParameter(“ name &quot;);
  • 15. Context Parameters Can create in general tab
  • 17. Configuration Parameters Accessing from servlet: Get the servlet configuration ServletConfig config = getServletConfig(); Get the webapp context from the configuration ServletContext context = config.getServletContext(); Get the value corresponding to the name of the parameter String value = context.getInitParameter(“ name &quot;); Accessing from a JSP: String value = application.getInitParameter(“ name &quot;); Built-in object in JSP (like “request”)