Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP wanted to redirect and product pop up

Status
Not open for further replies.

dognobbler

Programmer
Jul 4, 2003
46
0
0
GB
On the following page

I want the browser to be forwarded to the URL begining
and to pop up another window containing the URL -
The code I am using to do this is show below but it is currently only forwarding and not showing the pop up.

Can anyone tell me why this might be?



<%@ page language="java" %>

<html>
<head>
</head>


<body>

<script type="text/javascript">
var popurls=new Array()
popurls[0]="

function openpopup(popurl){
var winpops=window.open(popurl,"","width=100,height=100,toolbar,location,status,scrollbars,menubar,resizable")
winpops.blur()
window.focus()
}

openpopup(popurls[Math.floor(Math.random()*(popurls.length))])

</script>




<%

String strURL = request.getParameter( "URL" );
String strA = request.getParameter( "a" );
String strG = request.getParameter( "g" );

response.sendRedirect(strURL + "&a=" + strA + "&g=" + strG);


%>
 
Yup, because your issuing a jsp command before the page renders. When you send a redirect its sent in the headers which is before your javascript.

Remember, jsp is compiled so the CODE path is not as you expect it to be. Your java is putting the redirect on top and thus no pop-up.

The only way around this is to just allow javascript to do the redirect as well, no need to put that in jsp. Then javascript can pop the window first before it redirects. When javascript does a redirect it can directly address the window the URL is seeing in real-time, its at a level of the request phase the jsp can not access (JSP only can access BEFORE the request executes, not during). Thats why you can do it in Javascript and not JSP.

 
I do not know javascript, could you tell me the code I need to use.

Thanks

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top