Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet-controller  RSS feed

 
nandakumar yathirajula
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why servlet is used as controller why not JSP page?
[ December 29, 2004: Message edited by: nandakumar yathirajula ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is a complement to servlet. Servlet is not really good at presentation, therefore JSP came. JSP can do whatever a Servlet can, but JSP is not really meant for that. In other words these are not the alternatives of each other. Both have a different purpose.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You certainly could use a JSP as a controller but I'm not sure why you would want to.

With the doPost and doGet methods there to be overridden, servlets are perfectly laid out for the task. JSPs are nice for the view tier because they look to a web designer, like HTML, PHP, ASP pages but while coding the control flow, it's nice to be in a pure Java environment.

Also, with servlets as the controllers, you can tighten security to your app by denying direct access to JSP pages. This way the only URLs that run on your server are those that you've defined in your deployment descriptor.

You could hammer a nail with the back of a wrench if you had to.....
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cent percent agreement with Ben.

If you look further in JSPs we have somemore complements like JSTL, Custom Tags Libs, EL, to discourage the use of scriplets even. One of the primary purpose of these stuff is to implement the tag like structure in JSPs. So it looks more like HTML, ASP, etc. We are encouraging web developers to use JSP no matter they know java or not.

Using JSP as a controller is not right, as Ben explained quite well, and I believe in doing right things.

cheers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!