1

I need to redirect one html (A) to another (B).

I wrote function f in javascript that posts to (B) and put it in (A).

I am calling this function in body's "onLoad".

Now, I am accessing (A) page from browser. Redirection works good and I immideately see the (B) page.

But when I am doing the request to (A) page from java code, I get the content of (a) page itself, and not the redirected one.

How can I solve this problem?

Pez Cuckow
  • 14,048
  • 16
  • 80
  • 130
Matvey
  • 163
  • 2
  • 10

3 Answers3

0

I am not sure if I understood you correctly.

In java you are getting the page A because its what you requested. You are not getting the page B there because the javascript you added is in the client side. It seems that what you need is to redirect from java instead of javascript

Guito
  • 1,181
  • 1
  • 9
  • 19
0

When you do the request to page A using the browser, it will get the response from the server (the full HTML source for page A), then it will execute Javascript code, that will in turn make your browser to issue a new request to page B.

When you access the page from your Java call, the onLoad handler will not get executed. You are just getting the HTML code from page A (the same as the browser gets when it makes the request). Makes sense now?

You won't get the redirection to work, because it's happening at the browser's level, it's the browser that executes your handler for onLoad event.

Using server-side redirection you might be able to get the results you expect.

asm00
  • 689
  • 5
  • 6
  • What do you mean "server site redirection" ? Can I do it with javascript ? – Matvey Jan 15 '14 at 12:09
  • Well, I'm not that familiar to JSP pages in Java, but a quick search on the matter returned that you could use `getRequestDispatcher` to forward a request for a page into another resource. Take a look here: http://stackoverflow.com/questions/18576159/automatically-redirect-from-one-jsp-page-to-another and also here http://stackoverflow.com/questions/15052037/redirecting-to-another-page-with-javascript-and-jsp – asm00 Jan 15 '14 at 16:24
0

Is this what you wanted?

<meta http-equiv="refresh" content="0; url=http://example.com/" />
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Universal Omega
  • 206
  • 1
  • 5
  • 26