SERVLETS AND JSP

can any one tell me in which place we can use SERVLETS and which place to use JSP.
[103 byte] By [prash317160] at [2007-9-26 3:44:23]
# 1

No hard and fast rule really, but here's my policy:

For very small projects, I use exclusively JSP. This allows rapid application development, but at the expense of maintainability. But for small projects, the tradeoff is worth it since I can deliver them very quickly.

For medium size projects, I move all business logic into JavaBeans and only put my presentation logic in the JSP. For example, my JavaBean would fetch a list of names from a customer database, but my JSP would translate that list into an HTML <select>.

For large scale projects, I follow the same design as medium size projects, but make my JavaBeans EJB's instead.

Notice there was no mention of servlets. I'm not a big servlet fan since JSP can do almost everything a servlet can do and are much faster to develop with. Servlets execute faster than JSP since the code is less bloated but I've never come across a project where it really made a significant difference.

There are two exceptions (in my opinion). If you want to stream out non-HTML or WML to the browser, a servlet is better suited to do this (although it can be done with JSP too). The other exception is the infamous Model-View-Controller design pattern but I haven't used MVC yet.

There's no right answer here but this formula has worked well for me. Whichever design you use, here's a big tip:

Don't put too much Java code into your JSP. If you do, it becomes very hard to maintain and will start to run slow too. If you're page contains too much Java code, your project is probably becoming a medium size project and you should start using JavaBeans.

Hope this helps!

jpardi at 2007-6-29 12:24:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...