3 Java Server Pages
3 Java Server Pages
2. Easy to maintain
✔ JSP can be easily managed because we can easily
separate our business logic with presentation logic. In
Servlet technology, we mix our business logic with the
presentation logic
Advantages of JSP over Servlets
Fastof Servlets
3.Execution Development: No need to recompile and redeploy
basically involves Six basic steps:
Syntax is as follows:
<% java source code %>
Example of JSP scriptlet tag
<html>
<body>
<% out.print("welcome to jsp"); %>
</body>
</html>
expression tag
Theofcode
• Execution placed
Servlets basically within
involves JSP expression tag is written to
Six basic steps:
methods.
• The code written inside the jsp declaration tag is placed
outside the service() method of auto generated servlet.
• So it doesn't get memory at each request.
• Syntax of JSP declaration tag
• <%! field or method declaration %>
Implicit Objects
There
•Execution are 9 JSP implicit objects.
of Servlets basically involves Six basic steps:
HttpServletResponse.
• The instance of HttpServletResponse is created by the
web container for each jsp request.
• It can be used to add or manipulate response such as
redirecting responses to another resource, send error etc.
JSP config implicit object
In JSP,
•Execution config is an implicit object of type ServletConfig.
of Servlets basically involves Six basic steps:
type ServletContext.
• The instance of ServletContext is created only once by the
web container when application or project is deployed on
the server.
• This object can be used to get initialization parameter
from configuration file (web.xml).
• It can also be used to get, set or remove attribute from the
application scope.
session implicit object
In JSP,
• Execution session is an implicit object of type HttpSession.
of Servlets basically involves Six basic steps:
Key Features:
Public default constructor.
Implements Serializable.
Getter and setter methods for properties.
Purpose:
Simplifies data management and interaction in server-side
Simple Example of Java Bean Class
Execution of Servlets basically involves Six basic steps:
import java.io.Serializable;
public class UserBean implements Serializable {
private String name;
private int age;
public UserBean() {} // Default Constructor
public String getName() { return name; }
public void setName(String name) { this.name = name; }
<jsp:getProperty name="beanName"
property="propertyName" />