What is JavaServer Pages?
JavaServer Pages was launched by Sun Microsystems in the year 1999. JavaServer Pages is called as JSP in short. JSP is an expedient technology that enables the developers to build dynamic web pages. Generally, stand alone Java code is embedded within static HTML page to form JSP. Additional JSP tags will be used to specialise the functionality of a web page. Rather than HTML, JSP pages can also be formed from XML or other document types. JSP files can be deployed and executed with the help of a web server like tomcat.
Why to use JSP?
-
JSP provides significantly enhanced performance since JSP embeds dynamic elements within HTML Pages itself
-
JSP files will always be compiled before it is being handled by the server for further processing
-
JSP are constructed over Java Servlets and they are translated into servlets during execution. Thus, JSP gets access to all the predominant API’s of Enterprise Java, together with EJB, JDBC, JAXP, JNDI, and much more
-
Simple applications can have only JSP pages. Complex applications can have JSP as part of MVC (Model View Controller). In MVC Architecture, JSP acts as a View Component wherein JavaBeans will play the role of a Model and Servlets will be the Controller
-
Most importantly, JSP is a vital portion of J2EE, a complete environment for building enterprise applications. This indicates that JSP can be used in diverse applications ranging from simple straightforward applications to the most complicated and demanding
Sample JSP Page
Here is a simple JSP Page that displays “Have a Great Day” ten times:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>J2EEReference.com Sample JSP Page</title> </head> <body> <h1> Sample JSP Page from J2EEReference.com</h1> <% for(int index=0;index<10;index++){ %> <h5> Have a Great Day!</h5> <%}%> </body> </html> |
Output of the above program is: