Hi,
It depends on what you want to do. After all a servlet is a compiled jsp, so there is not that much difference. Yet, you can create one servlet, or a servlet that calls other classes / methods to do a multitude of things whereas I often think of a jsp page as a means to an end to pass parameters and create a view page etc.
It's down to individual preference, and your mood on the day, but I think jsp are definitley more powerful for controlling the application.
best,
kev
ps. take allok at some examples of servlets and jsp's before making your own mind up. I have moved from jsp to servlets through laziness, I think.
They want to use JSPs for tasks that involve mostly user interface (HTML) issues, and servlets for tasks that involve mostly logic issues such as input validation. I have often seen the recommendation to have your links start a servlet that validates and processes the request parameters, then forwards to a JSP to produce the output. The theory is that Java programmers can work on the servlets and UI designers can work on the JSPs, but I don't know how much that happens in real life.
There are certainly differences.
1. You can talk to simple java beans using JSP easily.
2. JSP programmers need not require huge java knowledge, mainly they are Fron-end developers/designers.
3. If they know, what method to call and where to put the results, thats enough.
4. Where as servlet require java knowledge.
5. Servlets can do many things that a JSP can't do. For example writing binaty data (stream) to the browser. You can't get another stream writer in JSP, it will throw exception.
More, if you start searching.
Sudha
A good reason to use both servlets and JSP together in web applications would be to implement an MVC pattern. If you do that all common tasks such as authorisation and handling of resources are centralised in the controller. This could be implemented as a jsp but since all it contains is programatic logic it is neeter to implement it as a Servlet. This then dispatches to the views which are implemented as JSP's. There's loads of info about this and where it might be usefull on the J2EE blueprints section or you could look at apache's struts project which is an open source MVC implementation.
In my old app, I used Servlets. In the Servlet, the HTML code was in the servlet, so was the business logic, so was the database access.
Now I use JSP for the new app, and I have JSP with HTML, JavaBeans for logic, and other JavaBeans for db access.
Thus, I've made my app more modular. Don't forget though, JSP's are Servlets. It's just a different way to look at things. On the server, they really do just about the same thing.
> In my old app, I used Servlets. In the Servlet, the
> HTML code was in the servlet, so was the business
> logic, so was the database access.
>
> Now I use JSP for the new app, and I have JSP with
> HTML, JavaBeans for logic, and other JavaBeans for db
> access.
>
I think this setup is becoming the norm. Constructing your HTML inside a JSP is no problem at all, whereas with servlets, it required a little thinking, and usually some debugging too. Putting all your backend logic in JavaBeans is wonderful, and leaves your JSP pages "clean" of all the behind the scenes stuff, and lets them worry about interpreting the information and displaying it correctly.