• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Servlet » Chaining » Servlet Chaining Between Two Servlet Programs
Next →
← Prev

Servlet Chaining Between Two Servlet Programs

By Dinesh Thakur

In the diagram Below, Srvl program forwards the request to Srv2 only when the generated square value is less than 100,otherwise, the Srvl directly sends response to browser window displaying that square value.

Deploy both these web applications in web logic server (Adv.java Batch Domain) copy WeqAppl, WebApp2 web applications to <oracleweblogic_home>\user-if possible \domains \Adv.javaBatchDomain \autodeploy folder.

              Servlet Chaining between Two Servlet Programs of two different web applications which resides in the same server

In the Srvl servlet program of the above WebAppl web application, we must create RequestDispatcher object based on ServletContext object.

             

            

Source Code (WebApp1)

input.html url patttren of Srvl servlet program

<form action=”slurl” method=”get”>

             A value : <input type = “text” name= “t1”><br>

            <input type= “submit” value= “getResult”>

</form>

Srv1.java

import javax.servlet.*;

import javax.http.*;

import javax.io.*;

public class Srv1 extends HttpServlet

{

     public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException

   {

            PrintWriter pw = response.getWriter();

            response.setContentType(“text/html”);

            int no=Integer.parselnt(req.getParameter(“t1”));

            int res1=no*no;

            if (res>=100)

               {

                  pw.println(“Srv1 : Square val is :”+res);

               }

            else

               {

                  ServletContext sc1 = getServletContext();

                  ServletContext sc2 = sc1.getContext(“WebApp2”);

                  RequestDispatcherrd = sc2.getRequestDispatcher(“/s2url”);

                  rd.forward(req,res);

              }

   }

}

web.xml

Configure Srvl program with /srvlurl as url pattern’

 

Source Code(WebApp2)

Srv2. java

import javax.servlet.*;

import javax.http.*;

import javax.io.*;

public class Srvl extends HttpServlet

{

     public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException

   {

            PrintWriter pw = response.getWriter();

            response.setContentType(“text/html”);

       int no=Integer.parselnt(req.getParameter(“t1”));

       int res2=no*no*no;

       pw.println{“Srv2: cube val is :”+res2) ;

  }

}

You’ll also like:

  1. What is Servlet Chaining?
  2. Type of Servlet Chaining
  3. Types of Java Programs
  4. What is the Servlet container raises the life cycle events in servlet program?
  5. RequestDispatcher in Servlet
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW