Solved

problem with sendRedirect() in netscape

Posted on 2001-07-29
10
164 Views
Last Modified: 2013-11-24

hi,

I have the following servlet code

res.sendRedirect("/KrizmMail_S/servlet/KrizmMailServlet?current_folder=inbox");
it is working fine in ie 5.5
but in netscape 4.7  it gives the message
This page has
 moved to <link>here</link>

my system configuration is redhat linux 7.1,apache,tomcat.

plz. help me to solve this problem.

thanx in advance.
merson

0
Comment
Question by:merson
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
Is everything on the same server?

Are you using SSL with the page?

These are just some of the scenarios when I've had a similar kind of issue.

The only way that I got around it was not to redirect but "connect" directly to the URL using the URLConnection class, reading the response in and then outputting it directly to the browser.

:o)

Ant
0
 
LVL 3

Expert Comment

by:black
Comment Utility
it happens because the response.sendRedirect method sends a response back to the browser requesting it to go to another url. You should be able to change the configuration on the browser so it follows redirects. I know it's a setting in IE but I'm not sure about Netscape
0
 

Author Comment

by:merson
Comment Utility

hi marsh,

i have everything ( servlets,html files, images...)
on the same server.
and it works fine with ie 5.5.

could u plz. give me details of the code u suggested


merson
0
 
LVL 3

Expert Comment

by:dnoelpp
Comment Utility
I suggest you to use <jsp:forward> instead. sendRedirect just tells the browser to go to another url. This might not always work. And there are additional round-trips. Like this:

Browser: Give me http://www.yourserver.com.
Server:  Please read http://www.yourserver.com/index.html instead.
Browser: Give me http://www.yourserver.com/index.html.

You get the picture? <jsp:forward> however just gives the other file immediately.

If you work with servlets use this instead (does the same):

getServletContext().getRequestDispatcher(otherUrl).forward(request, response);
0
 
LVL 3

Expert Comment

by:black
Comment Utility
you cannot forward to a page that is not on your webapp i.e. if you have a webapp called "myWebApp" which maps to the following url
/myWebApp
on your App Server, you cannot redirect to
"http://blah.com"
you can only redirect or forward to resources within "myWebApp"
for example if you did
getServletContext().getRequestDispatcher("/index.html").forward(request, response);
it actually maps to
/myWebApp/index.html

you could do that and simply have a meta tag in that file which tells the browser to redirect to another page, or have some java script but either way you've got to tell the browser what to do.

Ant's way would work but with issues.
Basically you can create a new URL to the place you want and download the content but reading it's input stream and then writing the content back to the browser. But if it has any relative links to images, or other pages they will be intepreted by the browser relative to your url therefore unless you modify each of those links any relative images and anchors will be broken. I did some work on doing this exact same process and had to parse the entire input as an XML document and modify all anchor, image, base, etc... tags that had any relative links. If it has javascript to create links then it's pretty much impossible.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:dnoelpp
Comment Utility
Yes, you are right. I just assumed the page merson wanted to redirect to is on the same web application.

/KrizmMail_S/servlet/KrizmMailServlet?current_folder=inbox definitively looks like being on the same web app. Or am I mistaken?
0
 

Author Comment

by:merson
Comment Utility
thanx guys

i want to redirect to the same webapplication itself

merson
0
 

Author Comment

by:merson
Comment Utility

hi,

i hust changed the code
from

res.sendRedirect("/KrizmMail_S/servlet/KrizmMailServlet?current_folder=inbox");

 to

res.sendRedirect("/KrizmMail_S/servlet/KrizmMailServlet");


now it is working.

but don't know what went wrong  in the first case


merson
0
 
LVL 3

Expert Comment

by:dnoelpp
Comment Utility
Really strange, huh? :-)
0
 
LVL 3

Accepted Solution

by:
black earned 200 total points
Comment Utility
I think it's because you had parameters in the first instance and Netscape wanted confirmation before a url was called with parameters. I believe it's for security so the user doesn't unwittingly submit data and are not aware of it.
It probably is better for you to forward it causes less network traffic, and it's done on the server side so it's guaranteed to work always.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Increment alphanumeric sequence 6 79
factorial example challenge 10 61
Updating Java 9 87
array11 challenge 16 51
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now