2

A same question can be found here . and some equal questions found.
They are about javascript (answer :-window.top.location.href = "http://www.site.com"; )
But
I want to know how to redirect it by Java in a jsp page. A usual redirect can be done as..

response.sendRedirect("newUrl.jsp");  

But it redirects the source page inside the iframe not the parent page. The task is that the source file of the iframe get refreshed and do some stuff(checking session.. getting attributes. )and if the source page meets a particular logical stage,then the parent page might be redirected to another page.But not in javascript, I want to know it in JAVA( That means the jsp/servlet container decides and redirects to another page in the server).
My current opinion is that, such things might be handle with javascript.Your all info is highly appreciated.

Community
  • 1
  • 1
Débora
  • 5,816
  • 28
  • 99
  • 171
  • The only way you can 'watch' for changes in an iframe is to use javascript. There is no way to do it *purely* in any server-side language. – James Hay Apr 17 '12 at 04:44

2 Answers2

1

Instead of sending a 301 or 302 redirect, send a JSP page (or write to the output stream of the response) with html content that has the javascript redirect in it set to execute on load. That way you can do your checking in the java side of things and just send the javascript redirect when appropriate, otherwise send regular content.

digitaljoel
  • 26,265
  • 15
  • 89
  • 115
  • Thanks digitaljoel. Your idea is good.but (As I understand what you mean..) if a jsp page is sent, it loads inside the iframe itself again and the parent page not redirected. Also, sending html elements and javascripts is also good.But I want to redirect in the server side(by the container.)Once again thank you for your idea – Débora Apr 17 '12 at 04:53
  • I just tried it and it worked fine, redirecting the parent window. If you only send the html content with the javascript redirect when your java code would normally like to call response.sendRedirect then it shouldn't effectively be any different to you than calling response.sendRedirect. Obviously you have issues if javascript is disabled, but I don't think you have many other options. – digitaljoel Apr 17 '12 at 05:06
1

I have scenario like:

We have an application deployed on WebLogic and one application deployed on tomcat. we have embeded tomcat application to run in WebLogic application. somewhere we want to redirect the page on WebLogic application URL which is the parent application. for that if you use: response.sendRedirect("newUrl.jsp") it will redirect to inner application URL(tomcat).

to resolve it I have used JavaScript for redirection

<%
boolean isRedirect = true // check if redirection required, I have made it true for testing
String redirectHomepage = "home.jsp";
if(isRedirect){
%> 
    <script type="text/javascript">
        window.parent.location.href = "<%=redirectHomepage%>"
    </script>
<%
    return;
}
%>