File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JavaScript section in JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JavaScript section in JSP Page" Watch "JavaScript section in JSP Page" New topic
Author

JavaScript section in JSP Page

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hello,
I have a Javascript section in my JSP page as follows:


What I am confused about is, if I navigate away from this page, and then navigate back to it, it does not appear as if this section of code is re-evaluated the second time I visit the page. Is this correct? How would I make it be evaluated? I need to because the value of qList and thus the value of quarters should change between the page visits.

Thanks very much for any info!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

if I navigate away from this page, and then navigate back to it


By that do you mean using the Back button? Or navigating back to the page through links?

I'm assuming the former. And in this case, the Javascript will be re-evaluated, but not the JSP code. Think about it for a minute. When you hit the Back button you are telling the browser to show the page again out of its cache. So all that's happening is that the orginal page that was sent is being re-displayed. No server. No JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hi,
I am navigating to the page through links, the first time I visit the page, I click a link which brings me to a differant page, then I click a submit button on that page which brings me back to the origional jsp.

It appears that the html for the page is being correctly redrawn, but the values set in the javascript are not being refreshed.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

OK, that's a bit different, but perhaps not too much.

It may be the case that when you navigate back to the page, the browser is pulling the old page out of cache. First step is to check whether the browser is actually going back to the server and re-executing the JSP page.

A simple way to check this could be to add some log statements to the JSP code and check whether they get written the second time the page is hit.
[ November 03, 2004: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JavaScript section in JSP Page
 
Similar Threads
Focus on textfield when loading JSP
EL cannot get my bean attribute with "." operator
dojo and javascript DOM issue
Help needed with DOJO and JSP
JSP with JavaScript and Comments