Servlet interaction techniques

In our examples so far, we have demonstrated various servlet concepts and techniques. In most cases, these examples consisted of stand-alon...


In our examples so far, we have demonstrated various servlet concepts and techniques. In most cases, these examples consisted of stand-alone servlet programs that handled a request and returned a response.

In the real world, servlets would not be stand-alone programs, but rather, they would be grouped together as part of an application; and the application components could consist of servlets, shared objects, and other resource files, such as HTML and JSPs. 

It would be expected that the servlets of an application would need some way to communicate and interact, either with each other or with the resources of the application. The ServletContext object, which we describe in more detail in “Application level scope” on page 89, provides a way for us to define this Web application level, and the resources that it can access and interact with.
This section describes various techniques for servlet interaction and communication. We will discuss the following types:

❑  Servlet collaboration: Two techniques for servlet collaboration are servlet filtering and chaining.Here multiple servlets collaborate on producing a single response for a client. The servlets themselves are not really interacting directly with each other, rather, the Web application server is
responsible for tying the servlets together.

❑  Calling servlets from servlets: Since servlets are Java programs, they can do anything a standard Java program can do, such as make a network connection. In this way, we have implicit servlet interaction. Additionally, because a servlet is just a Java class, we can instantiate and call a servlet’s public methods.
❑  Response redirection: We can redirect the servlet response to another application resource, such as another servlet or an error page (HTML or JSP). 

❑  Request dispatching: Through the RequestDispatcher object, we can forward a request to another servlet, which can handle the request and return the response. Additionally, we can include directly another servlet’s response within the context of a calling servlet. We can use request dispatching to dispatch the handling to another active application resource.

❑  Resource usage: We can interact with an application’s resources through the servlet context. The ServletContext object allows us access to these resources through the getResource method.

❑  Sharing of objects in scope: There are three levels of object scope for a servlet. Application scope is between all servlets in the same application, and is accessed through the ServletContext object. User session objects are accessed through the HttpSession object, and request level objects through
the servlet request.
Name

ADO,131,ASP,3,C++,61,CORE JAVA,1,CSS,115,HTML,297,index,5,JAVASCRIPT,210,OS,47,PHP,65,SAD,53,SERVLETS,23,SOFTWARE ENGINEERING,245,SQL,71,TCP/IP,1,XHTML,9,XML,18,
ltr
item
Best Online Tutorials | Source codes | Programming Languages: Servlet interaction techniques
Servlet interaction techniques
Best Online Tutorials | Source codes | Programming Languages
https://www.1000sourcecodes.com/2012/05/servlet-interaction-techniques.html
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/2012/05/servlet-interaction-techniques.html
true
357226456970214079
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content