Right structure to work with java (JSP)

Asked

Viewed 545 times

1

I’m starting to develop with java (Jsp). And I would like to know the correct structure of working (only with java "pure").

Would that be:

model (Classes with get and set) dao (classes that extend the connection class) (for each class of the model package I have a DAO that accesses the database)

need to have another package to have the business rules? or should I implement in the model?

  • 3

    Hi @Teuassuri, how are you? It is a little difficult to answer such a broad question of architecture because there is more than "a correct way" to draw the layers of an application in java, it all depends on your project. On one side we have Martin Fowler talking about the dangers of anemic models, on the other, years and years of "procedural" culture and service layer design (whether in EJB projects, Spring projects, etc). I don’t know if this helps, but what I can say is, get information on rich domain and business layers, use what’s best for your project (which can be both ;).

  • 3

    Another relevant comment... If you’re going to work with "pure" web java (whatever that is), don’t forget the Servlets. They play an important role: to interact with the business model and/or layer, to control navigation, etc jsps may be limited to the layer of view. Avoid scriptlets and things like that; leave your layer of view clean; the Servlets "Frontals" should take care of all this and do forward for the jsps, the latter must be "donkeys" (show only results).

2 answers

1

Since you asked about patterns...

The most common is the MVC(Model-View-Controller):

  • Model: Class where is the business logic and logic of the program. EX.: Ejbs, Beans, Daos.
  • Controller: Class that takes requests made by View and passes them to the Model.
  • View: Class that displays data to the client. EX.: JSP or JSF pages

On "pure java", just use it in classes and Servlets, NEVER do this on JSP pages. Instead, look for an alternative, such as JSTL.

I advise you to take a look at some tutorials on the internet, about MVC in general. To learn more about the pattern, I used this MVC tutorial in PHP, Wikipédia’s English MVC page and the Thejavageek tutorial for MVC in Java.

0

Hello,

I would indicate that you start with the basics, take simple examples of MVC(Model-View-Controller) patterns to start your architecture and web java studies.

Here, below are some interesting links about java web, using very basic MVC architectures.

Caelum’s Java web workbook, which covers everything from the basics of Java web to the use of more complex frameworks such as Spring MVC, as well as presenting standards for essential projects such as DAO Pattern (Data Access Standard): https://www.caelum.com.br/apostila-java-web/

Simple tutorial in English very fast: http://www.thejavageek.com/2013/08/11/mvc-architecture-with-servlets-and-jsp/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.