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.
I'm studying for SCWCD and trying to get an understanding of the practical side. I've written a little web app, and wanted to check that the following makes sense and is good practice.
The user clicks a link and this is mapped in web.xml to a servlet.
So my Controller here is a java class extending HttpServlet.
This will do some logic and talk to other java components (the Model).
The Model returns a bean which the Controller attaches to the request and forwards to a JSP (the View).
Does that sound correct? And are Controllers typically java classes or is there a reason for implementing them as JSPs themselves?
Doug Braidwood wrote:At the moment the web-apps I'm building as I learn only have a couple of Controller servlets so Front Controller is probably overkill.
Once I've got SCWCD what do you think is most sensible to learn next? I thought maybe Struts and Hibernate?
Don't learn Struts 1 unless you really, really need to, or want to learn it for historical purposes. There are an arbitrary number of web frameworks (of which Hibernate is not one) you could learn; Struts 2, Spring MVC, FrontMan, Wicket, Tapestry, JSF, ... Which to choose depends on your goals and ambition.
Doug, Just a note, to keep in mind that the concept of a Controller is a "design" concept. And the Model-View-Controller object-oriented design pattern is also a "design" concept. There can be many, many different ways to implement the design, with different programming languages or with different implementation designs using the same programming language.
The Struts Controller implementation consists of many more files than a single Java servlet class, for example. There are parts of the Controller that are open-source and then there are parts that a developer codes and then there is one or more XML-based configuration files which are created by the developer. The open-source parts of the Struts Controller are integrated with the proprietary parts that are created by an organization. This is why Struts is called a "framework." The open-source parts do nothing by themselves, they just give you something to build upon.
Hope this helps. Also Struts 1.X is still used in many, many organizations. So there is a significant value to learning it . Struts2 is a different take on MVC concept and can be considered a different framework altogether (which just cannibalized the popular "Struts" brand-name.)
Doug Braidwood wrote:
At the moment the web-apps I'm building as I learn only have a couple of Controller servlets so Front Controller is probably overkill.
Yea, I said that once.
Then one more component, then another, ......
With each one, it becomes more and more work to make the transition.
Do yourself a favor and start it right from the beginning.
We have a very simple example of the command pattern with MVC in the Servlets section of our CodeBarn.
I wouldn't use it for a large production app but it is a quick way to have a small working example on your desktop in under 5 seconds.
Once you get the gist, take a look at some of the ones that David mentioned earlier. They'll save you a lot of work when your project gets bigger.