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

Welcome to IWETHEY!

New When does a java constructor execute?
Java classes can have a 'main' or a constructor. If there is no method with the same name as the class it is considered to have an implicit constructor. I think I'm clear that the class that represents to top level of the application will have a 'main' and that the objects that are instantiated will have constructors.

I've got a servlet that had code in the constructor that initialzed a variable. The jsp page calls a method that returns the value of that variable. It returns null. I copied the code from the constructor into the other method and it returned the right value, so I know the code was right. I tried renaming the constructor to 'main', thinking maybe a servlet is called more like an app, rather than instantiated like an object.


My question (in several parts) is: When do I use 'main' and when do I use a constructor with the same name as the class?

What determines whether the constructor is executed?

Do the answers to the above questions depend on whether I'm doing a standalone application, vs a servlet, vs a class that will be called by other classes?

In the following:
\n<jsp:useBean id="packagename" class="packagename.ClassName" scope="session"/>\n<jsp:setProperty name="packagename" property="*"/>\n\n<html>\n<head><title>Foo</title></head>\n<body>\n\ntest: '<%= packagename.method() %>'
I assumed that the 'useBean' line was creating an instance of the class, and that the constructor would execute. Do jsp pages typically not instantiate servlets? Would I need to create a 'new ClassName()' somewhere within the jsp for the constructor to be executed?
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New When you say 'new'
Java classes can have a main *and* a constructor. They are completely unrelated concepts.

Servlets are a little odd because:

1) There is exactly one instance handling all requests - so ivars have roughly the same scope as static vars in a servlet.

2) You don't instantiate the thing - the servlet runner does that

3) The servlet runner typically calls the default no-argument constructor

4) Construction time isn't always the best time to initialize things and interesting services you might depenend on might not be alive yet which is why

5) Servlets have an init() method that gets called and this is where you should probably do your actual initialization - should look something like:
\npublic void init(ServletConfig config)\nthrows ServletException\n{\n    super.init(config); // let super class init as well\n    // initialization code goes here\n}\n

The gory details are spelled out in fairly long winded format here: [link|http://www.oreilly.com/catalog/jservlet/chapter/ch03.html|http://www.oreilly.c...chapter/ch03.html]



"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 Word from the IGM on ziwt says ... I was wrong
I was using the servlet for the wrong thing. Learning the language, I just took the sample code I wrote for a command-line app and made it into a servlet. In that context, the class I was using (a DB connector) should have been called by an servlet, it shouldn't have been the servlet itself.

I'm still getting my head around which part of the app should be in the servlets and which should be called by the servlets. Would I be way off base to say that model/view/controller maps roughly to object/jsp/servlet?
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New I think you've got it
Would I be way off base to say that model/view/controller maps roughly to object/jsp/servlet?

No, that's about the right division of responsibilities.



"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 Would be nice to say that in the docs
Sun has a ton of great docs about MVC and other programming theory. They've also got a ton of very explict language documentation. What they don't have is anything that says, "And here is how you use this language to execute this theory."
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New That's missing for most languages
Which is why Scott Meyer's Effective C++ books were so good. They were the first and best to answer just that question.



"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 Like Drew, I'm trying to teach myself Java.
Your post just cost me \ufffd7; I picked up a copy of Bloch's "Effective Java".


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New "Effective Java" => oxymoron :-)
New "Microsoft Works"
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New What would he know about it?
He wrote the collections library.

Its not a particularly good collections library.

Several of us Smalltalk guys tried to point that out to him when he introduced it at JavaOne many years ago (like 1998 I think).

He didn't want to hear it.




"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 That's an oddly visceral response.
I'm not sure I buy the idea that because he wrote a library that some people don't like, everything he possibly has to say on the subject of Java is null and void.

Anyway, wossisface Gosling who invented Java seems to like it, right enough.


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Symptomatic of general J-headed attitude
Please, lets not learn anything from anybody else. This is all so wonderfully new and shiny and we made it all up by ourselves with our eyes closed and nobody could possibly know more than we do even though we're getting it wrong pretty often and we've set general programming back 10 years with all of our shite.

"Anyway, wossisface Gosling who invented Java seems to like it, right enough."

case rest.

I went to a talk yesterday - some wanker going on and on about AsspectJ and how it simplifies this and adds that and isn't it all magic its the new OO going to be the wave of the future. Nevermind that it doesn't work with dynamic invocation (via reflection) or that it suddenly confounds all the debuggers that we just got working reliably after years and years of printout based debugging.

Its taken a million J-monkeys something like 5 years just to make aspects work reasonably seamlessly. On squeak guy took a look at it and hacked out AspectS in a weekend. Just to see if it would be helpful. I don't think anybody's bothered to use it but there it is - a simple api on top of the meta object protocol to do the aspect "weaving". Turns out that its hardly worth building a whole facility for it when you can write a couple thingies in a few minutes to do the same thing.




"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 Re: Would be nice to say that in the docs
I wish I could find something like that in Squeak docs - I think I get all the pieces of Morphic, but not the entire picture.
--


- I was involuntarily self-promoted into management.

[link|http://kerneltrap.org/node/4484|Richard Stallman]

New That's it exactly
Reading the language specification, I feel like I'm looking at a catalogue of screws and bolts. Each piece is described in excrutiating detail: load-bearing capacity, shear strength, thread count and pitch, driver required, accessories. But nothing saying why you'd pick the 6-inch lag bolt vs. drilling through and using a machine bolt, nut, washer and lock washer.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New I'd give up on Morphic
Its about to be replaced with Tweak.

Tweak is a ground up new thing - its a little side project of Croquet. There is work to rewrite all the programming tools in tweak - once this is done then Morphic and MVC are going to be excised from the image.

[link|http://minnow.cc.gatech.edu/squeak/3867|http://minnow.cc.gatech.edu/squeak/3867]




"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 Now I'm getting frustrated (again)
According to [link|http://www.oreilly.com/catalog/jservlet/chapter/ch03.html|O'Reilly]:
It enables persistence. A servlet can have already loaded anything it's likely to need during the handling of a request. For example, a database connection can be opened once and used repeatedly thereafter.
This is explicitly saying that a DB connection ought to be in a servlet. So who's actually written servlets in anger? What works? Putting the db connection in a servlet, or in an object that a servlet calls? What factors should I consider when making this decision?

BTW I figured out why my servlet init wasn't being called: I didn't import javax.servlet.*; and extends HttpServlet. I still don't have it working, but I know at least one step I was missing.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Re: Now I'm getting frustrated (again)
I "open" connections for every request. Since the connections are pooled, effectively I only have as many open as I need, and I never need to worry about sharing one. A connection has to be committed all at once, so if you have multiple threads sharing the connection, opportunities for badness abound.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Badness
Covering that in detail this term: bakery algorithm etc.

Serious badness, indeed:)
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
New Servlets and business logic
Strictly, I don't write servlets as I use the Struts MVC framework and write extensions to a servlet instead. You should not put a DB connection in a servlet because this is putting business and persistence logic in the presentation layer. This is poor architecture and asking for unmaintainable code. If you want to write an SMS gateway and message interpreter, for example, you're stuck as existing code is mixed up with web page workflow logic.

That you already asked "or in an object that a servlet calls?" means you already understand this. Moving the business and persistence logic into separate packages means future presentation layers can use them. And it's easier to maintain overall. If it's not over-engineering, separate this into an EJB (Enterprise JavaBeans) server such as JBoss or Weblogic. EJB is annoying but it can reduce concurrency and transaction headaches.
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.
New So is this example stupid?
[link|http://www.yolinux.com/TUTORIALS/LinuxTutorialTomcat.html#DATABASE|http://www.yolinux.c...cat.html#DATABASE]

This is representative of what I find googling for how to do db connections with servlets. I'm fairly sure this should be, "How not to do it."

Can anyone point to an example of a servlet connecting to a separate DB object?
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Hell, yeah!
The example isn't even thread safe. A JDBC connection isn't fond of multiple, open Statements and there's no synchronisation. Unless the result set is being kept open for a reason, it and the statement has to be wrapped in a synchronized statement, where the data is dumped into some custom, data object. Only process data outside the critical section to reduce bottlenecks.

Or how about having HTML mixed up with Java. You can't show that to a web designer. If a web designer gives you a web page with the typical, artistic crap in it, it's painful to make a servlet emit it. And then someone will want the look and feel of the website completely changed. That's what JSP's for! A tutorial that teaches JSP but doesn't demonstrate it. Ummm...

If you're not going to learn an MVC framework like Struts, the servlet should extract the raw, data objects appropriate for a page from a core, business model then forward to a JSP page that formats them for display. Separating responsility means more maintainable code.

Following the tutorial means putting the hideousness of JDBC in every page controller. Separate this stuff into a core, business model, for the love of god!

And there's error trapping after writing part of the response, so it's too late to forward to a general error page with a contact 'phone number, apology or whatever. And if workflow has to be changed, such as mistyped data that must be corrected or a rejected transaction, the servlet is forced to emit the appropriate output for all eventualities, which is duplicated across many servlets. Rather than working out to which servlet to forward. Control logic comes before view logic.

I doubt I can give you some links as I now do the Struts-JBoss thing, which is a completely different brand of horror.
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.
New Re: Hell, yeah!
I use Spring in Tomcat. For Java stuff it's pretty nice. No EJBs to deal with, but you still get any transaction stuff you need. And the Inversion of Control configuration with Spring is very useful.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Way stupid
Threads - definitely. Whole body of doGet() should be wrapped in a big

synchronized(dbcon) { ... }

Then it would have a prayer of being correct (although you are now single threaded and thus not too scalable). This example really hilights the stupid decision to not construct a new servlet for each request.

Also, it doesn't close the db connection in a destroy() method - so you could end up with a mess of hanging connections over time during development.

What are you trying to do BTW?



"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 Trying to learn The Right Way[tm]
Right now, I've got two ideas for an application to practice on. One is the ever-popular photo album. The other is an admin piece for my online store. Either one is something that I can do by hand more easily than write an app, but I need something to practice on.

Basically, I already understand the advantage of MVC ... I've been trying to do it since before I knew the term for it. I know the db connection shouldn't be in the jsp. I didn't think it should be in a servlet, either, but that's the only examples I could find. All the servlet examples are self-contained, never including other objects.

The O'Reilly servlet page did cover enough about thread-safe servlets to confirm the db shouldn't be in one. I would think by now, with as many people writing java as there are, someone would have put up a step-by-step guide to writing jsp using servlets to connect to a db object. Maybe once I've written it I'll twikify it.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New No such way
really, it depends on what you want to do.

If you were to write an app to do basic db admin - its likely that you'll only have one user at a time and so minimal thread safety and simplicity is going to get the job done and frankly I wouldn't invest any more effort into it than taking the above mentioned servlet and wrapping sychronized block on the connection.

But - if you are going to have more users you need to think more about scalability. Its not free though. Consider a weblog app - one author and a bunch of readers - again you can use the above naive approach with some caching (keeping records in memory as maps) for the read-only uses.

OTOH, maybe you want to write a store - now you could have lots of updaters with people adding items to carts, entering shipping info, etc. So each users probably ought to get his own records cache and you should create a connections pool. Pools are dead easy to write - or you can just go find one somewhere. In fact, I just found one for you.

[link|http://proxool.sourceforge.net/|Proxool] is used by cheap bastards travel. What it does is let you write naive db code and sneaks in a pooling implementation under it. IOW you can write

\nClass.forName("org.logicalcobwebs.proxool.ProxoolDriver");\nconnection = DriverManager.getConnection(url);\n...\nconnection.close();\n


and getConnection actually acquires a connection from the pool. Closing the connection puts it back into the pool. That'll get you scalability on the cheap for simple stuff.

Keep in mind that MVC is not a panacea. You have to decide about model sharing and concurrency issues. For a blog, I'd have one model shared among all users. For a store, each user should get his own model/context. For a really big store, writeable objects should pop up in individual contexts, but read-only objects want to be in a shared context.

Notice that more users results in more work though.




"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 I need to write a small app like it's a big one
First I'll learn how to make it scalable and bulletproof. Then I'll worry about when I can ignore some of that.

As for MVC being a panacea, that's not what I'm thinking. I think that keeping it as a goal makes it more likely I'll ask the questions that may prevent pain farther down the road. I'm more interested in the fifth iteration of a project than the first.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Huh, most people are trying to figure out the opposite
Seriously, just do the simplest thing you can and get it working. Then we can help you elaborate and refactor.

Something like proxool will take you pretty far if its just a crud app.



"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 This is classic
You're driving straight towards the overdesigned application which solves a ton of problems that you weren't ever going to have, and is a complete PITA to work with because of all of the overhead. Plus if it ever did get under load it would fall over because somewhere you'll have a design problem, and because the design is heavyweight, it will take more work to track that down and fix.

Remember that a scaleable application is like a mack truck. Great when you need it, but not very convenient for the daily commute.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Um, ...
Couldn't you write that first paragraph as a general description of any Java application development endeavor?

[image|/forums/images/warning.png|0|This is sarcasm...]

bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
New No. Exceptions exist. But generally, yes.
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Not exactly
You're driving straight towards the overdesigned application which solves a ton of problems that you weren't ever going to have ...
Keep in mind what problem I'm actually trying to solve: passing an interview for a java position. I need to be familiar with the techniques for heavyweight development.

In my current job, 90% of what we do each day could be done by a decent programmer who's known the language for about a month. I suspect a lot of internal development is the same way. Draw a form, process the input, update the database, show the results. If we interviewed for that, we'd never know who could handle the other 10%.

So no, I don't need a scalable interface for managing my photos. What I do need is a practice project I can use to learn the techniques I will need for large projects.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Good luck
There are many sets of buzzwords that might be applied to a given large project. You'll need luck to pick the same set for your personal project as your interview wants...

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Ah - so that's what you're trying to do
You didn't say so.

The thing is - most of that kind of architecture is approached incrementally starting with naive and simple and then benchmarking and refactoring as appropriate. A few things are sort of self-evident. Like thread safety is worth pursuing from the beginning. But more elaborate load distribution techniques are typically approached incrementally.

You might do better to do some [link|http://www.amazon.com/exec/obidos/tg/detail/-/0764543857/qid=1107306865/sr=8-2/ref=pd_bbs_2/102-2959288-0102521?v=glance&s=books&n=507846|reading].

For my money, Rod Johnson is pretty much the most objective writer on J2EE out there.



"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 Time to hit the library
Hope they have it in. They tend to be about a year behind on Java, and that's a 2003.


Interesting thing I found while looking around for used copies of it. In [link|http://www.theserverside.com/articles/article.tss?l=RodJohnsonInterview|this interview] the author says:
Some of the most important parts of the framework used in the book aren't available in existing projects. For example, the JavaBeans packages are more sophisticated than existing equivalents such as the Apache BeanUtils that came from Struts. I would have loved to find a similar JDBC abstraction layer but I couldn't.
I'm currently downloading the db framework you pointed me at, but it looks like for some reason jdbc frameworks seem to be lagging a lot of other pieces.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New That's an old interview.
What you want is the [link|http://www.springframework.org|Spring framework], which is basically everything Rod talks about in his book as an actual project, and then some.

We're using it at work and it's a beaut as far as Java frameworks go. JDBC made sane, EJB-like stuff without EJB headaches, etc.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Gold mine
[link|http://www.theserverside.com/articles/article.tss?l=SpringFramework|This] and even moreso [link|http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html|this] are what I was looking for.

Peter, check them out.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Moochos grassy arse


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Several copies of Rod's book around here.
It's useful for defusing "I read about this nifty J2EE thinger on the web"-itis.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Q on book.
At your recommendation I bought that book. Then, I changed responsiblities at work (no longer a developer). But I am now responsible for setting up things like Tomcat (and later maybe JBoss) and making sure they're always online. I'm reading up on Tomcat 5 right now (Professional Tomcat 5 by wrox) and I have it running (my still remaining trick is to get an iSeries "Webfacing" app running on it - along with a list of other stuff that has to be fixed). From strictly an admin's POV, would I be better off to go through Rod's book first or, realizing that I will likely never actually write a Java app, would you recommend any other book(s)?

TIA.
bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
New Rod's book isn't for administrators
Although you're likely to find some material of use, you're better off finding a Tomcat-specific book like you have.

If you anticipate getting into arguments with developers about the Right Way to Do Things, then his book would probably be useful from the standpoint of understanding what's going on and how things should be architected.

Check the contents to see if there aren't a few deployment chapters at the end or what not, though. I don't have my copy handy.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Ok, thanks.
bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
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.
New Re: When does a java constructor execute?
You might want to try just downloading Tomcat, go over its documentation, and build a simple app from that. The database access should be fairly trivial, given the fact that Tomcat already has a connection pool and example code and configuration on how to set it up (access datasource via JNDI).

If you're writing a web app, you should probably just ignore servlets completely (for now). There are JSTL tags to use to make direct SQL calls for small apps. At some point, when the app gets bigger, you'll want to move to hibernate, JDO or something like that for you db access. For now, direct SQL in JSP is probably fine (hence, get used to refactoring).

I don't know that Tomcat has docs that will hand-hold you through it, but if you start down that direction, there's enough skill on this board to help walk you through it (though it may take a little while). Creating a db-based web app should be fairly simple and easy (once you've done it a couple of times).

Dan
New There is a certain amount of value...
... in doing an application the small, stinky way at first, just to appreciate what the frameworks are actually buying you later on.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New I already know that
I've built my own PHP frameworks, and now use the PEAR stuff extensively. I don't have to be sold on that. Like I said above, I need to know enough to pass an interview. Learning a framework first will only help if I go somewhere they use the same one.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New s/Tomcat/Jetty/
Tomcat is a dog.

Jetty is a lot like Tomcat only better performing and a bit simpler to setup I think.



"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 Based on what?
Here's the only benchmark comparison I've been able to find so far. The methodology is somewhat suspect, however, but useful if you understand what they did.

[link|http://www.webperformanceinc.com/library/ServletReport/|http://www.webperfor...ry/ServletReport/]
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Personal experience
TC gave me frequent failed connections when used as servlet container in JBoss a couple years back. Replacing with Jetty drop in replacement resulted in much improved performance.

Its all subjective - I did no measurements other than observe that my app sucked way less under Jetty than Tomdog



"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 A couple of years back, sure.
Tomcat 5 is a lot faster.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Oh Tomcat 5
Oh very nice.

I freely admit that I don't know anything about it. My experience was with version 4.somethingorother.

Ground up rewrite was it? There's so much endless crotch fondling in J-land that I can't really keep up with the latest wave of [link|http://www.artima.com/weblogs/viewpost.jsp?thread=86833|stuff they just figured out] that everybody else has [link|http://www.cmcrossroads.com/|known] for years (one little representative example).

Its nice to hear that at least some of the churn has a forward vector component.




"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 Reminds me of Spolsky's piece on Netscape
[link|http://www.joelonsoftware.com/articles/fog0000000069.html|http://www.joelonsof...og0000000069.html]
New And I remember disagreeing with it the first time
My opinions then: [link|http://www.perlmonks.org/?node_id=115724|http://www.perlmonks.org/?node_id=115724]

My opinions haven't been updated since then other than to point out that now even Joel considers Mozilla a success. Furthermore he doesn't respond to the fact that the Netscape 4 code, after having proprietary bits ripped out so that they could open source, didn't run! The decision to rewrite came after looking at rewriting from scratch vs having to do a lot of work to get working code, followed by having to solve all of the problems in that code base.

Another grumpy opinion from me. Refactoring is great. By all means do it. But living in the middle of a code mess that someone is trying to refactor is kind of like living in a house that's under constant renovation. You're not sure which tap has hot water this week, and you're really praying that the showers aren't hooked up to the sewage system. (I know someone that this actually happened to!)

Refactoring is a tool. It is not a pancea. And it is not always the right tool.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Makes sense to me.
I was going to post a quip like, "Yeah, FireFox shows how bad a decision it was to throw out the Netscape code." You made the case much better.

Sometimes you really do need to start over. It may be true that it's done far too often, but sometimes it is the appropriate choice.

Joel often rubs me the wrong way. I've only read ~ half a dozen of his posts, but his I-used-to-work-at-Microsoft-so-I-know-how-to-write-software / apply-for-a-job / whatever-better-than-you attitude grates sometimes.

People who make decisions he looks back on in hind-sight and disagrees with aren't all idiots. Borland and Netscape were done in more by MS's anticompetitive actions than by coding decisions...

My $0.02.

Cheers,
Scott.
New Know what you mean
its a pity he couldn't take his own advice on UI design while working at Microsoft.

He was just here to give a talk. I didn't sit through it but I popped in for a few minutes to get the gist of what he was on about. 90 seconds into it I just thought "well, duh" and walked out.




"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 It's a threshold thing
From a commercial standpoint, a total rewrite of Netscape would have bankrupted any company that did such a thing. I'm glad that Mozilla rewrote the browser from the ground up, as it is a much better offering as a result. But the time involved also saw Netscape's market share fall off the end of the world. This is a case of Open Source keeping something alive where the shrink wrap world could not have possibly survived.

The bigger problem is not that you should never rewrite like Joel says, but when is it technically and economically justified. The threshold for rewriting from scratch needs to be set high simply because a lot of developers lapse into the mindset that it will cure all the ills in one fell swoop.
New And that point is completely true
Complete rewrites are much more affordable when you don't have to care about details such as market share. It does leave you with a lot of work and no shipable product while competitors are producing improvements.

There are no easy solutions to that. Just think of how long the road was for Microsoft to replace Windows 3.1 with Windows NT. (I think we all know that Windows 95 was not, despite many claims otherwise, actually a complete rewrite...) And I think that they handled it pretty well.

As an ironic example of not doing it so well, I'd like to point at Microsoft's current problems with Internet Explorer 6.0...

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
     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)

Coding all day leaves you in a state of mild aphasia as you look at people's faces while they're speaking and you don't know they've finished because there's no semicolon.
157 ms