• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

can JSP be used as controller in MVC

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a JSP be used as controllor in MVC architecture ? If NO, why
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Can a JSP be used as controllor in MVC architecture
Yes it can be.
With a JSP you can do anything a servlet can do.

However what would be the point?
A controllers purpose in life is to look at the request, and then dispatch it to the appropriate handler.
A JSPs purpose in life is to produce an html page for display.

While you CAN use a JSP for a simple controller, I don't see anything about JSPs that recommend it for the job.
If you are writing scriptlet code - why isn't it in a servlet?
I suppose the <jsp:forward>, <jsp:include> tags combined with the some conditional logic could provide a controller, but only really for the simplest of controllers.

Bottom line: yes you can use a JSP for a controller, but there are more appropriate alternatives. Use the right tool for the right job.
 
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
Yes, and I could pound nails in with the back of a wrench if I needed to.
I'd prefer to use a hammer though.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yes, you can use JSP as a controller in MVC.

Basically there are two models of MVC.
1.MVC1
2.MVC2

In MVC1 architecture Jsp acts as a controller as well as processing the client request.But mvc1 architecture is best suited for small applications.

In MVC2 architecture Servlet acts as a controller.Struts framework uses MVC2 architecture.

Thanks,
march
 
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
That's Model1 and Model2.
Model2 is MVC.
Model1 is not.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please remember that everything in the JSP API is designed to serve character streams. If your application ever needs to serve binary data such as PDFs, images, sound files, etc. having a JSP as the initial request handler will cause you endless trouble. Just "bite the bullet" and learn how to use servlets - it really is quite easy.
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic