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.
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) ;
}
}