1

I would like to ask a question on how I decided to implement the MVC pattern for a simple javaEE application (when I say javaEE I mean pure javaEE without any additional framework, so: servlet, jsp ejbeans...). My mvc works in this way:

Actors:

  • view -> a set of jsp pages;
  • controller -> a single servlet;
  • model -> a set of non-instantiable java classes containing static methods.

Functioning: each user request is managed by the servlet which decides the correct static method to call among the classes of the model. In particular, each form in the jsps contains 3 hidden fields: classToCall, methodToCall and destionationPage. Once the servlet receives the http post, it reads these 3 hidden fields and

  1. call the right method in the right class via reflection passing the HttpRequest as parameter
  2. forwards the user to the correct jsp which displays the result of the computation.

My main doubt regards the implementation of the model as "static" classes: since many frameworks tipically handle user requests by creating a bean on the fly and calling an instance method of it, I would like to know if my "static" model can have any "contraindication".

Thanks a lot for your help, bye Nico

Nico Tanzarella
  • 179
  • 1
  • 9
  • possible duplicate of [Design Patterns web based applications](http://stackoverflow.com/questions/3541077/design-patterns-web-based-applications) – BalusC Nov 02 '11 at 13:23

1 Answers1

0

:) you can use jsf 2.0 is integrated in javaEE6 :) and is pure java ee :)

here is an overview: javaEE 6 overview

Don't try to reinvent this.. :) jsf 2.0 also has ajax integrated :) you only have to write jsf and not jsp... :) or you can write both... jsp and jsf... but I recommend you only jsf

But if you want to write your own... I do not recommend you use static functions...

  • can not be overriden
  • less modular

You should use AOP and dependecy injection.. You might also want to make your own bean factory.. is not that hard.. I find it easy ... you just have to do some annotations for beans to see if it's a bean or something.. or just use an XML file to define your beans... and with reflection access them...

You can see more answers here: When NOT to use the static keyword in Java?

Community
  • 1
  • 1
Alex
  • 2,126
  • 3
  • 25
  • 47
  • Thanks Alex but this is not the answer I was looking for. I want to reinvent this even to deeply understand all the "problems" of standard javaEE which lead to such a great number of useful framworks – Nico Tanzarella Nov 02 '11 at 11:41