We know that Servlet is a server side technology, so why has Sun Microsystems given JSP?
Servlet is a Java code based programming. To know servlet, strong Java knowledge is required. However, while working with ASP.net, PHP like technologies we can go for tag-based programming which is easier. So in initial days programmer did not like Servlet. To attract non-java programmers like ASP.net programmers and PHP programmer Sun Microsystems has introduced a server side technology which is tag based all features of servlet.
JSP enables us to mix up static HTML with dynamically generated content of servlet. the Take example of an online-shopping website, its initial page is mostly same for all visitors, except small changes like welcome message “Hi Mr / Ms Xxx” for registered users. When we develop this by servlet then we have to develop this entire page by writing coding in the Servlet program. However, JSP makes separate parts for static content and dynamic content.
We’ll be covering the following topics in this tutorial:
Advantage of JSP over Servlet
JSP | Servlet |
Allows tag based programming. So extensive java knowledge is not required. | Does not allow tag based programming. So extensive java knowledge is required. |
Suitable for both java and non java programmer. | Not suitable for non java programmer. |
Use nine implicit objects, which we can use directly in our JSP program | Implicit objects are present but we can’t use them directly. We need write additional code to use them. |
Modification done in JSP program will be recognized by underlying server automatically without reloading of web application. | Here we need to compile and reload manually. |
Takes care of exception handling. | Does not take care of exception handling. Programmers have to explicitly handle this . |
Allows us to use separate presentation logic (html code) from Java code(business logic). | Does not allow. |
Increases readability of code because of tags. | Readability of code is less |
Gives built-in JSP tags and also allows to develop custom JSP tags and to use third party supplied tags. | Does not allow tag based programming. |
Easy to learn and easy to apply. | Not easy compared to JSP. |
Advantages over All Other Technologies
• Versus active server pages (ASP)
ASP is given by Microsoft. It is also a tag-based programming language. ASP code is not portable. However, JSP code is portable because it is written in Java (i.e., we can reuse the code in other operating systems and also in other web server). We can use Java for JSP, so we need not stick with a particular server product or IIS.
• Versus PHP
It is an HTML embedded scripting language and it is also open source software like Java. It is similar to JSP and ASP. It is not suitable for large scale application and banking applications where money transaction occurs because of security reasons. For PHP we have to learn one new language.
• Versus JavaScript
JavaScript is in no way related with Java programming. It is normally used to generate HTML dynamically on the client machine. JavaScript is not suitable for network programming and to access server-side resources. Java is more powerful, flexible, reliable and portable than PHP.
• Versus HTML
Regular HTML, that is static HTML, does not contain dynamic information. So it does not react to user input and is also not fit for accessing server side resources. JSP contains both static and non-static content. As static part, it contains HTML.