MVC without EJB

So I just started learning JSP/Servlets a couple days ago and have made some great progress. As I try to do things correct the first time I wanted to run my thoughts here and see if they are correct or completely off the mark...

I want to use MVC type architecture, I do not have an application server, and I do not want to use a framework (yet) so I am thinking this would be the best way...

Control = Servlet

View = JSP

Model = Servlet

The control servlet would be the input and would call whatever model servlet was needed for the processing and then everything would be outputted to JSP.

Am I a way off?

[652 byte] By [javaksa] at [2007-10-3 2:32:10]
# 1
> Am I a way off?Not too way off. Only that the Model should be implemented in POJOs, and the Servlet should limit itself to the Controller part.That would be MVC without EJB.
karma-9a at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Hi,

> I want to use MVC type architecture, I do not have an

> application server, and I do not want to use a

> framework (yet)

the MVC architecture (maybe better say design pattern because IMHO sw

architecture is "little bit more" than MVC) is very old thing ( ...Long ago, in the

70抯, Smalltalk defined an architecture to cope with this, called the Model-

View-Controller architecture1... Please see

http://en.wikipedia.org/wiki/Model-view-controller and

http://www.jdl.co.uk/briefings/MVC.pdf ). So your system surely can fulfil

requirements of MVC design pattern and don't need application servers,

frameworks, EJBs, JSPs and stuffs like that. BUT if you use them

PROPERLY then they save your time ( and you know "Time is money" :-) )

> so I am thinking this would be the

> best way...

>

> Control = Servlet

Could be a good choice.

> View = JSP

Could be a good choice.

> Model = Servlet

Even though I don't know exactly your architecture and intentions with this I

would dare to say that this is not good. Better will be to use "plain" java

classes (of course if you don't want to use frameworks, EJBs etc. ;-) ).

BUT the heart of the matter isn't in using JSP for view or servlet for view or

whatever. IMHO the heart of the matter is in low coupling between Model and

View and Controller and in high cohesion inside Model, View and Controller

( Please see

http://en.wikipedia.org/wiki/Low-Coupling_/_High-Cohesion_pattern and

http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29 ). If you

would like to learn more about basic patterns in context of analysis and

design I would recommend

http://www.amazon.com/gp/product/0130925691/ref=si3_rdr_err_product/104-6099108-0643149?ie=UTF8

for the beginning.

BTW. This http://java.sun.com/blueprints/patterns/MVC.html you know, hopefully ;-)

Message was edited by:

PetrG

PetrGa at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Thanks for the feedback. I looked up POJO's (I am really new to java) and I laughed when I saw the meaning. I will definitely play around with POJO's. And I will also be following all the links posted above today that I have yet to visit.

And I am open to frameworks, but I want to know how to code without it first.

As for something like JBoss, the host I currently have only has tomcat installed so for now I will have to wait as I am doing this mainly for my own personal self improvement.

So this is what I will start with...

Model = POJO

View = JSP

Controller = Servlet

Also, would you say learning an application server like JBoss is pretty important in the long run?

Message was edited by:

javaks

javaksa at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

> Also, would you say learning an application server

> like JBoss is pretty important in the long run?

>

Well, IMHO more important is to learn ideas. When you know how

technological things work ( for example EJB, JSP or Servlet) you will be able

to use them on every server which support them (JBoss, GlassFish or

WebSphere etc.). This is like driving a car. When you know it in one car you

are usually able to drive any car ( just you need to acclimate in a new car ).

But technology is only the base. You need to know as well:

- how to specify requirements

- how to design an architecture

- how to test

- how to lead projects

- etc.

- etc.

;-)

PetrGa at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...
# 5

I totally agree with you and understanding ideas/concepts is what I am mainly here for. Syntax I can find on the web. So going with that....

I do not want any html in my Controller/Model as I believe it should be in my View that would have scriptlets to get data and take care of any conditionals/loops. Now when my JSP loads does it call the model directly to get any needed data?

And instead of POJO's I was planning to use Java Beans for my Model which seems to be the same thing with a few rules.

Does this sound correct?

javaksa at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...
# 6

Generally what I do is to have the servlet (Controller) identify the objects (Model) that the JSP (View) is going to need, and put those objects into request scope. Then the JSP simply gets the request attributes and works with them. Sometimes it's necessary to put objects into session scope, if they need to be available for more than a single request.

Edit: And also, scriptlets are the previous generation of JSP technology. The current generation is JSTL; if you use that, then your JSP can be all tags and no Java. This is the inverse of the "no HTML in servlets" rule: "No Java in JSPs".

Message was edited by:

DrClap

DrClapa at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

DrClap,

Having the servlet identify the objects makes more sense. Thanks for that idea.

Now time to research JSTL. I am realizing that JSP is kind of a template page, with no server side code, which makes it easier for web designers to work on it and make it all pretty.

You guys/gals have been great!

javaksa at 2007-7-14 19:31:09 > top of Java-index,Other Topics,Patterns & OO Design...