aspose file tools*
The moose likes JSP and the fly likes can JSP be used as controller in MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "can JSP be used as controller in MVC" Watch "can JSP be used as controller in MVC" New topic
Author

can JSP be used as controller in MVC

sitaram irrinki
Ranch Hand

Joined: Feb 16, 2005
Posts: 158
Can a JSP be used as controllor in MVC architecture ? If NO, why
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
>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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
marchrose rose
Greenhorn

Joined: Jul 20, 2005
Posts: 3
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

Joined: Dec 11, 2004
Posts: 13410

That's Model1 and Model2.
Model2 is MVC.
Model1 is not.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12804
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can JSP be used as controller in MVC