This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello, I'm trying to figure out the scope of declarations. Here's some JSP code: ------------------------------------ <%!int count = 0;%> <% count++;%> this page has been accessed <%=count%> times. ------------------------------------- Whenever I resave the source file, the count starts over again at 1 and continues to increment every time I hit the page. Which makes sense. But when I switch browsers from IE to Opera, it starts again at 1. So I'm trying to figure this out, is the scope of a declaration based on the session -- does the JSP sessionID get sent back and forth thru a cookie? Or am I seeing this because of a browser cache issue? I was originally under the impression that a declared variable such as this is shared between all instances of the page for all users of the page? apparently this is incorrect -- can someone lay it down for me please?? thanks mucho Scottie Zman
Interesting Q... From my experience, im pretty sure the count of the integer is more related to JVM than session or application. As long as the jvm is running and jsp file doesnt get recompiled(when u save), a copy of the variable exists for all sessions and every user across the application. And i couldnt simulate the different browser initializing the counter to 1. (if it is... i might have to go back to understanding web fundamentals ) cheers, mpr
Yes, that varaible should be shared accross instances. I tried it, and it's working for me. i.e. One instance of the servlet is loaded, and the counter is incrementing accross both browsers. Verify that it's not recompiling when you load it up in the other browser. Also, make sure that you are not implementing the "single thread" model interface somehow.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joined: Aug 08, 2001
What causes a jsp to recompile? Only if you edit and then resave it, and then when the page gets accessed, correct? Is there anything browser-related that could cause it to recompile? Is this feature of JSP dependable enough that I could store a big chunk of XML with, say, an threads index to a bbs? thanks scottie zman
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com