why JSP as view in MVC model

Why Servlet as a controller?
  • If jsp is used as a controller we should write some java code to manage the flow of mvc application ,but writing  java code in a jsp page is against of industry standard ,so jsp is not suitable to act as a controller
  • If a bean is used as a controller then the bean class should trap the http request but bean is unknown about http protocol so bean is not suitable to act as a controller
  • Finally a servlet is suitable to act as a controller ,managing control flow of application 


Why  JSP is a view?
  • If a servlet is taken as a view then whenever we need modifications in presentation then we need to re compile the servlets ,reload the application  some times we need to restart the server,it ‘s time consuming process
  • If a bean component is used as a view then a bean should write response on browser but a bean is unknown about HttpRequest and http Response ,so bean is not suitable to act as view
  • JSP is suitable to act as a view ,it any modifications are done then just we need to resend the request from browser by clicking the refreshing 


Why Bean is Model?
  • If servlet is used as a model then the business logic implemented in servlet  ,also need more middle ware services from a container but a servlet runs in a web container and a web container provides less middle ware services to a servlets, more over servlet business logic becomes non reusable ,so servlet not suitable to act as model
  • If jsp is used as a model then we need to implement business logic in jsp page,but writing java code in JSP is against of industry standard,so jsp is not suitable to act as a model
  • Finally a bean is suitable to act as a model and bean gets more middleware services from it’s container then a servlet also business logic of bean becomes re-usability



No comments:

Post a Comment