Solved

servlet sendRedirect

Posted on 2014-03-27
1
706 Views
Last Modified: 2014-04-29
Hi,

I am reading about servlet sendRedirect as below

http://www.javatpoint.com/sendRedirect%28%29-method

orward() method      sendRedirect() method
The forward() method works at server side.      The sendRedirect() method works at client side.
It sends the same request and response objects to another servlet.      It always sends a new request.
It can work within the server only.      It can be used within and outside the server.
Example: request.getRequestDispacher("servlet2").forward(request,response);      Example: response.sendRedirect("servlet2");


I ran this example by creating fresh dynamic web project and copying src and web.xml, index.html files.
I redirected to google page as below

https://www.google.co.in/#q=sai

what is meaing of '#q '


I have not clearly understood the differences between redirect, forward.Advantages, disadvantage, practical uses of each of them.



please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39960746
A "forward" as the quoted text says, happens totaly within the server. It is basically just one servlet (the one calling forward() method) handing the responsibility of processing the request to a second different servlet. Note that this is totally transparent to the client, it knows nothing about this.

A "redirect" is a response that the servlet sends back to the client application (such as a web browser) that tells the client to go and look for whatever it is after at a different URL. Generally, the client/web browser will then make a separate request to this new URL to try and get what it is after. Obviously in this case, the client application is aware of what is happening, eg. if the client is a web browser, you might see the address change in the address bar.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Better way to make a string with template variables in java 3 34
Chrome and Firefox Java 5 69
Eclipse Java import and method not resolved 4 82
Java array 10 65
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question