• 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 » Difference Between Rd.Forward () Res. sendRedirect ()
Next →
← Prev

Difference Between Rd.Forward () Res. sendRedirect ()

By Dinesh Thakur

rd.forward (-,-)

res.sendRedirect (-,-)

  

• Performs forward rnode of servlet chaining.

• Performs sendRedirection mode of communication.

• The source servlet program communicates with destination web resource program directly.

• The source servlet program communicates with destination servlet program by having network round trip with browser window.

• The source servlet program and destination web resource program use the same request and response objects so the request data coming to the source servlet program is visible and accessible in destination web resource

program.

• The source servlet program and destination web resource program will not use the same request and response object so the request data coming to the source servlet program is not visible and accessible in destination program.

• The source servlet program can use the request attribute to send additional data to destination program.d

• The source servlet program and destination program can be there in the same web application (or) in two different application of the same server (or) different server.

• The destination program can be a servlet (or) JSP (or) HTML program.

• The destination sendRedirect operation the URL in the browser address bar will be changed.

• Suitable when the source servlet program and destination program resides in the two different web application.

• Suitable when the source servlet program and destination servlet program resides in the same web application.

Example on sendRedirect ()

Servlet program redirects the request to non-java web resource programs of websites hosted on the Internet.

The applications in the next page acts as a hub for working with multiple search engines.

The above application the servlet searchSrv redirects the request to search engine based on the search engine that is chosen in the form page.

To work with above application gather the web resource program names and

request parameter names of different search engines as shown below:

For google

http://www.google.co.in/search?q=new+seven+wonders

For Yahoo

http://search.yahoo.com/search?q=new+seven+wonders

For Bing

http://search.bing.com/search?q=new+seven+wonders

Develop the above web application

Step 1: Prepare the deployment directory structure of web application.Step 2: Develop the source code of above servlet program or web application.

Search.html

<form action= “surl” method= “get”>

  <center>

    <font color= ‘red’ size= ‘6’>

      <marquee behavior= ‘alternate’> SERCH ENGINE </marquee> <br> <br>

        SEARCH :<INPUT TYPE=“TEXT” height=‘45’SIZE=“50” NAME=“turl”> <br>

        <input type= “submit” name= “tsubmit” value= “search”> <br> <br>

          GOOGLE: <input type= “radio” name= “tradio” value= “google” CHECKED />

          YAHOO: <input type= “radio” name= “tradio” value= “yahoo/>

          BING: <input type= “radio” name= “tradio” value= “bing”/>

    </font>

 </center>

</form>

SearchApp.java

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

public class SearchApp extends HttpServlet {

  public void doGet(HttpServletRequest req,HttpServletResponse res)

   throwsServletException,IOException {

     //general Setting

     res.setContentType(“text/html);

     PrintWriter pw=res.getWriter();

     //read form data

     String s=req.getParameter(“turl”);

     String radio=req.getParameter(“tradio”);

     if(radio.equals(“google”)) {

      res.sendRedirect(“https://www.google.co.in/search?q=”+s);

     }

     elseif {

      res.sendRedirect(“https://www.yahoo.com/search?q=”+s);

     }

     else

      res.sendRedirect(“https://www.bing.com/search?q=”+s);

  }//end of doGet ()

}

web.xml

<web-app>

     <servlet>

        <servlet-name> abc </servlet-name>

        <servlet-class>SearchApp</servlet-class>

     </servlet>

     <servlet-mapping>

         <servlet-name> abc </servlet-name>

         <url-pattern> /surl </url-pattern>

     </servlet-mapping>

     <welcome-file-list>

        <welcome-file> home.html </welcome-file>

     </welcome-file-list>

</web-app>

Step 3: Compile the source files of all servlet programs.

Step 4: Configure all four servlet programs in web.xml file having four different URL patterns.

Step 5:  Start the server (Tomcat).

Step 6: Deploy the web application and Copy SearchApp folder to Tomcat_home\webapps folder.

Step 7: Test the web application.Open browser window type this url: https://ecomputernotes.com:2020/SearchApp/Search.html.

After clicking search button b, open web site in Google Search engine.

You’ll also like:

  1. How to use sendRedirect method
  2. How to use RequestDispatcher Forward method
  3. Difference Between Analog and Digital Signal | Difference and Comparison
  4. Write A C++ Program To Use Forward Goto.
  5. JSP Forward Action Tag Example
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