SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Web Component Development
with Servlet & JSP Technologies
(EE 6)
Module-5: Container Facilities for Servlets
and JSPs
Team Emertxe
www.webstackacademy.com
Objectives
Upon completion of this module, you should be able
to:
● Describe the purpose of deployment descriptors
● Determine the context root for a web application
● Create servlet mappings to allow invocation of a
servlet
● Create and access context and init parameters
● Use the @WebServlet and @WebInitParam
annotations to configure your servlets
www.webstackacademy.com
Relevance
Discussion – The following questions are relevant to
understanding what technologies are available for
developing web applications and the limitations of
those technologies:
● How can you write an application without knowing
everything about the environment in which it will be
used?
● How can you configure a web application if you don’t
have access to the command line that launched it?
www.webstackacademy.com
Deployment
Descriptors
● In versions of Java EE prior to EE 6, deployment
configuration was supported using the web.xml file.
● Because of the advent of annotations the web.xml file
is optional since Java EE 6.
● In addition to allowing configurationn to be done uisng
Annotations, another method of specifying deployemnt
information is also supported. This is the use of web-
fragment.xml file.
www.webstackacademy.com
The web-
fragment.xml Files
● The web-fragment.xml file provides a mechanism to
include deployment information that is specific to a
library, without having to edit the main deployment
descriptor for the whole web application. This reflects
the OO principle of keeping unrelated things apart.
● A web-fragment.xml file, located under the META-INF
directory of a JAR file placed within the WEB-INF/lib
directory of a WAR archive, will be read and the
configuration contained within will be integrated into
the configuration of the web application as a whole.
Note – Not all configurations can be achieved using
annotations.
www.webstackacademy.com
Controlling
Configuration
With three elements capable of providing configuration information,
web.xml, web-fragment.xml and annotations, it is possible for
these to provide conflicting information. To address this, some rules
and controles are provided. Three are particularly significant:
● Precedence
● <metadada-complete> Tag
● Ordering
● If desired, you can apply a <name> tag to an XML file, and using
that name, specify either an <absolute-ordering> or an
<ordering> tag to indicate the order in which configuration
elements should be applied.
www.webstackacademy.com
Dynamic
Configuration of
Web Applications
Java EE 6 adds features that allow the programmatic
configuration of servlets, filters, and related
components. This feature is only available as the web
application is being loaded, specifically during the time
that the servlet context is being initialized. It is perhaps
most useful for framework creators.
www.webstackacademy.com
Servlet Mapping in
web.xml
<web-app>
<servlet>
<servlet-name>MyServletName</servlet-name>
<servlet-class>com.emertxe.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServletName</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
</web-app>
www.webstackacademy.com
Multiple and Wildcard
URL Patterns
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
<url-pattern>/YourServlet</url-pattern>
<url-pattern>/HisServlet/*</url-pattern>
</servlet-mapping>
http://localhost:8080/MyAppRoot/MyServlet
http://localhost:8080/MyAppRoot/YourServlet
http://localhost:8080/MyAppRoot/HisServlet
http://localhost:8080/MyAppRoot/HisServlet/one
http://localhost:8080/MyAppRoot/HisServlet/twenty
www.webstackacademy.com
Mapping Using
Annotations
Since Java EE 6, servlet mappings can be achieved
using annotations. A servlet should be given the
annotation:
javax.servlet.annotation.WebServlet
This annotation supports various optional elements, but
a common form is that which has been used in
examples in previous modules:
@WebServlet(name="MyServletName",
urlPatterns={"/MyServlet", “/YourServlet”,
“/HisServlet/*”})
www.webstackacademy.com
Invoking a Servlet by
Name
A servlet can be invoked directly by its name through a
RequestDispatcher, in a forward or include call. The
necessary dispatcher is obtained using the servlet
context which offers a method
getNamedDispatcher(String).
www.webstackacademy.com
Servlet Context
Information
The deployment descriptor can include configuration
information for the servlet. Two configuration
elements of frequent utility are context parameters
and init parameters.
www.webstackacademy.com
Context Parameters
The term “servlet context” essentially refers to the web
application and the container in which the servlet runs.
An interface javax.servlet.ServletContext provides
access to several aspects of this environment, but in
the context of this discussion, the methods of interest
are two methods that allow read-only access to a map
of context Parameters. These methods are:
String getInitParameter(String name)
Enumeration<String> getInitParameterNames()
www.webstackacademy.com
Supplying Context
Parameter
Context cannot be supplied using annotations, because
they relate to the entire web-application, rather than to
a single element of it.
<web-fragment [...]>
<context-param>
<param-name>fragmentContext</param-name>
<param-value>fragment Context value</param-value>
</context-param>
</web-fragment>
Note: If this is done using a web.xml, then line 1 would
read <web..., rather than <web-fragment....
www.webstackacademy.com
Reading Context
Parameters
Context parameters can be read in Java code using
statements of the following form:
String paramValue =
this.getServletContext().getInitParameter("paramName");
Notice that the servlet (this) gives access to an object of
type ServletContext, which describes the configuration
of the application as a whole, from which the parameter
may be read.
www.webstackacademy.com
Servlet Initialization
Parameters
In addition to configuration parameters for the entire
application,initialization parameters can be associated
with the servlet individually. These are typically known
simply as init parameters. This association may be
achieved using the deployment descriptor.
www.webstackacademy.com
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>SL314.package.MyServlet</servlet-
class>
<init-param>
<param-name>name</param-name>
<param-value>Fred Jones</param-value>
</init-param>
<init-param>
</servlet>
Servlet Initialization
Parameters
www.webstackacademy.com
Servlet Initialization
Using Annotations
Because init parameters are directly associated directly
with the servlet, they can be specified using the
annotations mechanism. The annotation that would be
equivalent to the preceeding declaration would be:
WebServlet(
name=”MyServlet”,
urlPatterns=({“/MyServ”}),
initParams =
{@WebInitParam(name="name", value="Fred Jones")}
)
www.webstackacademy.com
Reading Servlet
Initialization Parameters
The servlet itself provides direct access to servlet
initialization parameters using the method
getInitParameter(String), and another method of the
same signature is provided in ServletConfig object. So,
these two lines of code, executed in the servlet, are
equivalent:
name = this.getInitParameter("name");
name = getServletConfig().getInitParameter("name");
www.webstackacademy.com
Other Configuration
Elements
● The deployment descriptor can contain elements of
many other types beyond those discussed in this
module. Similarly, several other annotations exist for
configuration purposes.
● While these are topics for later modules, you should
know that the deployment descriptor is used to
configure security, and connections to other aspects of
a Java EE system, such as Enterprise JavaBeansTM
(EJB),message queues, and databases.
Web Stack Academy (P) Ltd
#83, Farah Towers,
1st floor,MG Road,
Bangalore – 560001
M: +91-80-4128 9576
T: +91-98862 69112
E: info@www.webstackacademy.com www.webstackacademy.com

Contenu connexe

Tendances

Tendances (19)

Message properties component in mule
Message properties component in muleMessage properties component in mule
Message properties component in mule
 
SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3
 
Mule debugging
Mule   debuggingMule   debugging
Mule debugging
 
Logger
LoggerLogger
Logger
 
Logger
LoggerLogger
Logger
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3
 
Mule connector for ibm® as400
Mule connector for ibm® as400Mule connector for ibm® as400
Mule connector for ibm® as400
 
spring framework ppt by Rohit malav
spring framework ppt by Rohit malavspring framework ppt by Rohit malav
spring framework ppt by Rohit malav
 
Message properties component in mule demo
Message properties component in mule demoMessage properties component in mule demo
Message properties component in mule demo
 
How to use splitter component
How to use splitter componentHow to use splitter component
How to use splitter component
 
Configurare http mule
Configurare http muleConfigurare http mule
Configurare http mule
 
Configurare https mule
Configurare https muleConfigurare https mule
Configurare https mule
 
Mule ESB SMTP Connector Integration
Mule ESB SMTP Connector  IntegrationMule ESB SMTP Connector  Integration
Mule ESB SMTP Connector Integration
 
Mule esb
Mule esbMule esb
Mule esb
 
Anypoint connectorfor ibm as 400
Anypoint connectorfor ibm as 400Anypoint connectorfor ibm as 400
Anypoint connectorfor ibm as 400
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Htaccess
HtaccessHtaccess
Htaccess
 
Mule esb :Data Weave
Mule esb :Data WeaveMule esb :Data Weave
Mule esb :Data Weave
 
Refreshing mule cache using oracle database change notification
Refreshing mule cache using oracle database change notificationRefreshing mule cache using oracle database change notification
Refreshing mule cache using oracle database change notification
 

Similaire à Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 5 - Container Facilities for Servlets and JSPs

New Features Of ASP.Net 4 0
New Features Of ASP.Net 4 0New Features Of ASP.Net 4 0
New Features Of ASP.Net 4 0
Dima Maleev
 
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
Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Web Application Deployment
Web Application DeploymentWeb Application Deployment
Web Application Deployment
elliando dias
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Raghu nath
 

Similaire à Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 5 - Container Facilities for Servlets and JSPs (20)

Introduction to java servlet 3.0 api javaone 2009
Introduction to java servlet 3.0 api javaone 2009Introduction to java servlet 3.0 api javaone 2009
Introduction to java servlet 3.0 api javaone 2009
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
New Features Of ASP.Net 4 0
New Features Of ASP.Net 4 0New Features Of ASP.Net 4 0
New Features Of ASP.Net 4 0
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligeti
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
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
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
Web Application Deployment
Web Application DeploymentWeb Application Deployment
Web Application Deployment
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
 
Session 1
Session 1Session 1
Session 1
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
Introduction to java servlet 3.0 api javaone 2008
Introduction to java servlet 3.0 api javaone 2008Introduction to java servlet 3.0 api javaone 2008
Introduction to java servlet 3.0 api javaone 2008
 

Plus de WebStackAcademy

Plus de WebStackAcademy (20)

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
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
Earley Information Science
 
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
vu2urc
 

Dernier (20)

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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
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...
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 5 - Container Facilities for Servlets and JSPs