OK. The first thing you need to get used to when moving from PHP to Java is that a Java web application is mainly made up of regular Java objects rather than pages or servlets. The only purpose of a servlet is to handle the HTTP protocol. In a good design a servlet should be quite small and single-purpose, handing off all the processing to regular java classes.
So. Let's simplify your question to start with, imagine we only want a web application with just two "page zones" - a header, and a a main part. Let's start with a simple servlet which sits waiting for requests, and passes them to our two "zones":
Notice that we know very little about about these zones at the moment. They have a constructor taking a
string, and they have a method "generate" which takes a HttpRequest to get parameters and stuff from, and a Writer to write the output to.
To make this work in a very simple way, let's code a basic PageZone class:
Now,
you should be able to compile these two classes, place them in WEB-INF/classes in a servlet container, and run the servlet to generate an ultra-simple two-zone page:
To make the page zones smarter, there are loads of things you could do such as using the supplied name to find a file or directory containing chunks of HTML to show instead of the hard coded text. Or you could fetch information from a database. You have the whole power of the Java language at your disposal, and you might never need to change that servlet code again.
If you want to get really fancy, you could even change the servlet code a little to read the names of the classes to create for each of your zones from some sort of configuration file, rather than hard-coding them in the servlet.
For more suggestions and tutorials about writing, deploying and and
testing Java web applications, I suggest you check out my article series "Small and Simple Web applications, the Friki way", in the
JavaRanch journal I hope this has helped.