JSP(Java server pages) is API of J2EE which acccept request and generate dynamic Response.
JSP technology is used to create dynamic web application.
With respect to functionality JSP and servlet are one or same because JSP get
Transleted into servlet at Run time.
JSP Provide implicit objects, predefined tags, expression language which make your development easier.
Advantage of JSP.
- Easier to maintain
- If you change the JSP code then No need to re-compile and Re-deploy it again.
- Less code than Servlet
- JSP seperate business logic and presentation logic.
1. web designer can write presentation logic.
2. Web developer can write business logic to generate dynamic response.
In JSP you can write HTML and Java code but in case of servlet you can write
only java code.
When ever first request comes to JSP.
1. Container translate JSP into servlet.
2. Compile the servlet and generate class file(.class)
This class file used to generate dynamic response.
Hence the time taken to generate the response for first request is more compared
to subsequent request
Difference between JSP and Servlet
Simple JSP program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h1>This is JSP page</h1> <p> Javaforlearn is a platform where newbie programmer find a way to learn different Technology like java, J2EE, SQL, ODI , OBIEE and data warehouse concept.</p> <% //here you can write java code. //Printing simple message in console System.out.println("Hi Application is running "); //Printing simple message in Browser out.println("Hi This is Bhavesh Lakhani"); %> </body> </html>