Explain with the help of an example/diagram or write code for the following using JSP:
a) JSP life cycle.
b) Need of Directives in JSP with the help of taglib directive.
c) Use of scriptlet with the help of an example on displaying a number series from 1 to 10
d) The role of action elements in JSP with the help of an example of <jsp:usebean)
e) The purpose of using implicit objects in JSP with the help of an example.
a)
(https://www.tutorialspoint.com/jsp/jsp_life_cycle.htm)
b)
(https://www.guru99.com/jsp-actions.html)
<%@ taglib uri = "http://www.example.com/test" prefix = "mytag" %>
<html>
<body>
<mytag:subtag/>
</body>
</html>
c)
A JSP scriptlet is used to contain any code fragment that is valid for the scripting language used in a page.
(https://docs.oracle.com/javaee/5/tutorial/doc/bnaou.html)
<html>
<body>
<%
for (int i = 1; i < 11; i++){
out.println(i);
}
%>
</body>
</html>
d) These actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.
(https://www.tutorialspoint.com/jsp/jsp_actions.htm)
<html>
<body>
<jsp:useBean id="obj" class="mypackage.Test"/>
<%
for (int i = 1; i < 11; i++){
out.println(obj.power(i, 2));
}
%>
</body>
</html>
e) These Objects are the Java objects that the JSP Container makes available to the developers in each page and the developer can call them directly without being explicitly declared.
(https://www.tutorialspoint.com/jsp/jsp_implicit_objects.htm)
out - is the implicit object
<html>
<body>
<jsp:useBean id="obj" class="mypackage.Test"/>
<%
for (int i = 1; i < 11; i++){
out.println(obj.power(i, 2));
}
%>
</body>
</html>
Comments
Leave a comment