• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Separate classes for each features. Is it a MVC?

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I have created a login, register and query features. I am using Hibernate for persisting the data. But i have created Separate classes for each features, like LoginServlet.java, LoginDao.java, RegisterServlet, RegisterDao, QueryServlet, QueryDao. But I have also created different package for Servlet classes, and Dao classes. Is that ok? I guess that's not a perfect MVC. What all problems can i face in future as per this style of coding?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you have is a layered architecture where you have decoupled your presentation layer with persistence layer. When you implement an MVC, you need to present your view using JSP, FreeMarker, Velocity etc as well. You servlet should act only as a controller and should not be responsible for preparing the view for your request. It should dispatch the request to a JSP or appropriate view template after getting data from a Model (in your case DAO layer).

As for package structure, you can segregate them either by layer or by functionality and layer.

Layerd Package Structure

com.xyx.web.servlet.LoginServlet
com.xyx.web.servlet.QueryServlet
com.xyx.web.servlet.RegisterServlet
com.xyx.persistence.dao.LoginDao
com.xyx. persistence.dao.QueryDao
com.xyx.persistence.dao.RegisterDao

Segregating based on functionality and layer
com.xyx.login.web.servlet.LoginServlet
com.xyx.login.persistence.dao.LoginDao

com.xyx.query.web.servlet.QueryServlet
com.xyx.query.persistence.dao.QueryDao

com.xyx.register.web.servlet.RegisterServlet
com.xyx.register.persistence.dao.RegisterDao


 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Piyush. Yes, servlets just acts as a controller and dispatches the request to appropriate JSP. i also have a bean package where i have classes like LoginBean.java, RegisterBean.java, QueryBean.java. There is a jsp folder inside WEB_INF. It contains all the jsp files. Any other advices or suggestions.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kunal Lakhani wrote:There is a jsp folder inside WEB_INF.


Please note its WEB-INF, not WEB_INF..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic