'Redirect parent page from a ifram in JSP by JAVA

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.



Solution 1:[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.

Solution 2:[2]

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;
}
%>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 digitaljoel
Solution 2 Amarjit Kushwaha