Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javascript code is not called in jsp page  RSS feed

 
Abishek Maggo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have jsp page which actually redirect to another jsp page....
I need to run some javascript code before redirecting to another page

But it seems script got skipped & it goes to desired page.

code snippet:

I am expecting an alert "testing" before redirect to another page.

Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you are showing will not even compile. Please be sure to PostRealCode ⇐ click this

Regardless, what you are doing is not legal. You are just lucky that it does not result in an IllegalStateException.

What are you really trying to accomplish? Whatever it is, this isn't the way to do it.
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abishek, welcome to javaranch.

Your javascript code runs in the browser and you are doing a server side redirect. So the javascript is never sent to the browser which is why it never runs. If you want the javascript to run, you'll have to redirect the browser in javascript like
window.location=${param.url}
or something else like that after the alert message

[edit: bear beats the human (just kidding)]
 
Abishek Maggo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i need to track page through google analytics
So google analytics has provided me javascript code which i need to put in the page for which tracking is required

It is working with normal jsp pages but not with jsp page with redirection (as i need to track that page also per the requirement)

I understand from previous reply, server side redirection happening thats why javascript code never gets called/run

So i want that before redirection, my javascript code runs so that google analytics track/capture the page.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be no such pages. If all the page is going to do is to redirect, then this is something that should be done in the servlet controller before any JSP is invoked at all. Since this situation should never occur, your problem is solved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!