Q:- When servlets are there from Sun Micro Systems as server side technology what is need of jsp again from Sun Micro Systems?
A:- Before Servlets the software industry used to prefer to develop websites using asp technology of microsoft.
- This Asp is tag based technology. so it is easy to learn and easy to apply(working).
- Programmers were attracted this technology even after arrival of this servlet.
- Even though servlet's is having strong features and advantages compare to Asp.
- Because to learn servlets java knowledge is required and servlet's doesn't allow tag based programming.
- To overcome these problems of servlet Sun MicroSystems has designed a tag based technology called Jsp having all the features of servlets in the form of Asp style tag based programming.
- For every jsp the underlaying web application server generates an equivalent servlet.
Drawbacks of servlets:-
1. Strong java knowledge is required to write a servlet.
2. In Servlets we mixup Business logic means java code with presentation logic i.e html code. so any change in java code disturbs html code and vice versa.
3. Placing html code in servlets is little bit complex.
4. Exception Handling is not possible declaratively only programmatic(try & catch blocks)Exception handling is possible.
5. There is no support of any implicit objects in servlets.
6. Any modification in the source code of servlet will not be recognized automatically by the servers.
7. Recompilation of servlet, reload of total webapplication is required.
Features of Jsp's
1. It allows tag based programming. It is easy to learn and easy to work.
2. Every jsp internally maintains an equivalent servlet. so all the features of servlet's will be available in jsp's.
3. Since tags are there it is easy to learn for both Microsoft and Non-Microsoft programmers.
4. Supports page compilation. The process of converting Jsp's into an equivalent Servlet is called page compilation.
5. Any modification in jsp's will be recognized by webserver automatically.
6. Huge support for 9 Number of Implicit Objects.
7. Allows to handle the exceptions declaratively (xml code).
8. In Jsp java code will be separated from presentation logic html.
Note:-Initially software industry had utilized jsp as complete alternate for servlets. In the current situation software companies are using multiple technologies like servlets and jsp's together in web application development.
- Page compilers converts jsp into an equivalent servlet.
- In Tomcat server page compiler name is Jasper.
- In weblogic server page compiler name is Jspc.
Scriptlet:-
- It is a special tag which can contain java code. This java code takes care of dynamic values generation responsibility of Jsp execution.
Template Text:-
- Ordinate text plus html code both together we call as template text. This template text take care of fixed output values of Jsp response generation.
Template text = htmlcode + ordinary text
Example:-
- Template text in the jsp generates fixed values of jsp response. where as java code available in the scriptlet generates dynamically based on request time that is there when request comes to jsp