Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can JSP be used as controller in MVC

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a JSP be used as controllor in MVC architecture ? If NO, why
 
Stefan Evans
Bartender
Posts: 1690
10
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
marchrose rose
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's Model1 and Model2.
Model2 is MVC.
Model1 is not.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic