• 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

How to implement mvc using servlets

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All, Could anyone please give me an example on how to implement mvc design pattern using servlets and jsp. Any practical example would be helpful. Please do guide me on how to implement mvc using servlets and jsps. What's the role of each one of them in the example. Please also give me the links to resources to sites which explains the concept best. Thanks in advance.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlets section of our CodeBarn has some very simple examples.
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben, I saw the source code of the example given in Code Barn. Could you explain me the working of ControllerServlet.java




According to my understanding :
This ControllerServlet acts as a controller. In this servlet we are populating the model which in this case is ModelBean.We are setting the model in the request attribute which is modelBean. Then we are forwarding to view.jsp and passing the request and response. Please do clear my concepts.
I read that the controller performs some logic and then according to the result passes on the information to the view. Here where we are implementing some logic, we are simply passing the model to the view.
Another question, can I use Login validation as an example where I use a class Login as a Bean, then in the controller pass the username and password to the Login bean to do the validation. and then the bean passes on the result to the controller which according to the result passes on to the appropriate view.
I would like to clear my concept with a clear and simple example. Please do guide me. Thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like it is already clear to you.

Yes, this is a common way to write validation.
Often the model will communicate with an object that will perform a database look up on the username and password.
The important thing is that the servlet and JSP don't need to know that there is a database transaction going on. Likewise your data access objects should have no idea that they're being called from a servlet app.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic