IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New That's not what they are saying
Its a dumb example.

The servlet container (tomcat, jboss, whatever) constructs exactly one instance for each deployed servlet class and uses it to handle every single request.

This is a really annoying design choice as there is no nice way to have data that is page scoped without passing it around in all the calls. Hence my comment that ivars and static vars have roughly the same scope/lifetime in a servlet.

When they say persistence - they mean that the servlet instance stays around until the servlet is reloaded (container is bounced or source code is changed). So the values in the ivars are "persistent" from page request to page request.

What are you trying to do?



"Whenever you find you are on the side of the majority, it is time to pause and reflect"   --Mark Twain

"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."   --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."   --George W. Bush
New Servlets and page scoped variables.
As you say, only one instance is shared between simultaneous requests, so everything must be passed as function parameters.

What are they trying to do? In the grand scheme of things, business services are meant to be provided by something else, such as an EJB server. Servlets aren't supposed to do too much. Yes, I know that's a lame excuse and they could use instance pooling, much like EJB.

You're not supposed to use instance or static variables. Use the getAttribute() and setAttribute() from ServletContext for application wide, HttpSession for session wide and HttpRequest when passing control to another servlet.
Matthew Greet


But we must kill them. We must incinerate them. Pig after pig, cow after cow, village after village, army after army. And they call me an assassin. What do you call it when the assassins accuse the assassin? They lie. They lie and we must be merciful to those who lie.
- Colonol Kurtz, Apocalypse Now.
     When does a java constructor execute? - (drewk) - (56)
         When you say 'new' - (tuberculosis) - (41)
             Word from the IGM on ziwt says ... I was wrong - (drewk) - (40)
                 I think you've got it - (tuberculosis) - (11)
                     Would be nice to say that in the docs - (drewk) - (10)
                         That's missing for most languages - (tuberculosis) - (6)
                             Like Drew, I'm trying to teach myself Java. - (pwhysall) - (5)
                                 "Effective Java" => oxymoron :-) -NT - (ChrisR) - (1)
                                     "Microsoft Works" -NT - (drewk)
                                 What would he know about it? - (tuberculosis) - (2)
                                     That's an oddly visceral response. - (pwhysall) - (1)
                                         Symptomatic of general J-headed attitude - (tuberculosis)
                         Re: Would be nice to say that in the docs - (Arkadiy) - (2)
                             That's it exactly - (drewk)
                             I'd give up on Morphic - (tuberculosis)
                 Now I'm getting frustrated (again) - (drewk) - (27)
                     Re: Now I'm getting frustrated (again) - (admin) - (1)
                         Badness - (jake123)
                     Servlets and business logic - (warmachine) - (22)
                         So is this example stupid? - (drewk) - (21)
                             Hell, yeah! - (warmachine) - (1)
                                 Re: Hell, yeah! - (admin)
                             Way stupid - (tuberculosis) - (18)
                                 Trying to learn The Right Way[tm] - (drewk) - (17)
                                     No such way - (tuberculosis) - (16)
                                         I need to write a small app like it's a big one - (drewk) - (15)
                                             Huh, most people are trying to figure out the opposite - (tuberculosis)
                                             This is classic - (ben_tilly) - (13)
                                                 Um, ... - (mmoffitt) - (1)
                                                     No. Exceptions exist. But generally, yes. -NT - (ben_tilly)
                                                 Not exactly - (drewk) - (10)
                                                     Good luck - (ben_tilly)
                                                     Ah - so that's what you're trying to do - (tuberculosis) - (8)
                                                         Time to hit the library - (drewk) - (3)
                                                             That's an old interview. - (admin) - (2)
                                                                 Gold mine - (drewk) - (1)
                                                                     Moochos grassy arse -NT - (pwhysall)
                                                         Several copies of Rod's book around here. - (admin) - (3)
                                                             Q on book. - (mmoffitt) - (2)
                                                                 Rod's book isn't for administrators - (admin) - (1)
                                                                     Ok, thanks. -NT - (mmoffitt)
                     That's not what they are saying - (tuberculosis) - (1)
                         Servlets and page scoped variables. - (warmachine)
         Re: When does a java constructor execute? - (dshellman) - (13)
             There is a certain amount of value... - (admin) - (1)
                 I already know that - (drewk)
             s/Tomcat/Jetty/ - (tuberculosis) - (10)
                 Based on what? - (admin) - (9)
                     Personal experience - (tuberculosis) - (8)
                         A couple of years back, sure. - (admin) - (7)
                             Oh Tomcat 5 - (tuberculosis) - (6)
                                 Reminds me of Spolsky's piece on Netscape - (FuManChu) - (5)
                                     And I remember disagreeing with it the first time - (ben_tilly) - (4)
                                         Makes sense to me. - (Another Scott) - (1)
                                             Know what you mean - (tuberculosis)
                                         It's a threshold thing - (ChrisR) - (1)
                                             And that point is completely true - (ben_tilly)

Egged on by rogue sentient trees, some of them do wish it.
145 ms