Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1069785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:28:20+00:00 2026-05-16T20:28:20+00:00

All the online references and head first JSP&Servlet book I’m reading state the characteristic

  • 0

All the online references and head first JSP&Servlet book I’m reading state the characteristic of RequestDispatcher and Redirect (i.e. resoponse.sendRedirect() ) like:

“Request Dispatcher” – URL in the browser bar does not change.

“Redirect” – The user sees the new URL in the browser.

But according to my test, for RequestDispatcher, I am seeing the URL changes so I don’t understand what they really mean.

With the code below,

  1. I’m on http://whatever.com/tmp3.jsp and that’s what URL in the browser says.

  2. Click on the button to call servlet which in return it forwards the data to server then the server sends response back to the browser, so URL in the browser now says http://whatever.com/register

So.. URL changed! (from …/tmp3.jsp to …/register)

Can anyone explain to me what they mean by “URL in the browser does not change”?

Example:

(tmp3.jsp)

<html>
<head>
</head>
<body>
   ${message}
   <!-- click button to send request to servlet -->
   <form method="POST" action="register">
       <input type="submit" value="click!">
   </form>
</body>
</html> 

(servlet)

package com.masatosan.tmp;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Tmp extends HttpServlet {


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("message", "processed!");

        String address = "/tmp3.jsp";
        request.getRequestDispatcher(address).forward(request, response);
    }//end doPost()

}//end class

(web.xml snippet) – mapping the servlet and URL

<servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>com.masatosan.tmp.Tmp</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/register</url-pattern>
</servlet-mapping>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:28:20+00:00Added an answer on May 16, 2026 at 8:28 pm

    Two things happen here:

    • first you submit the form to the servlet, which always changes the URL
    • then you choose to redirect or to forward to a view – i.e. another (or the same) JSP

    For the second step:

    • redirect sends a special header to the browser, and it makes a new request to the page to which the redirect points
    • forward makes this internally, within the same request, and the browser never understands that it is not the resource it has requested

    In your example, the URL stays /register because you use forward. If you use redirect, it will first change to /register, and then it will change back to tmp.jsp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I've searched thoroughly online and here, without finding a clear solution
I have searched online but all the answers I have found were very primitive.
All the automated, online converters weren't able to convert this code. Unfortunately my brief
Gday All, I am developing a site that uses PayPal to take online payments.
I have an online dictionary. All inputs are saved in table id-word-unixtime. Now I
i have tried looking online but had no luck, How i could delete all
Ok, I have scoured online resources and applied all the suggested solutions. I am
Adobe Flash CS4 contains no documentation at all; it simply redirects to the online
I am working on an online typing software. In the typing software, all is
I've seen a pile of ways to do this online, but all that I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.