Answer to Question #282703 in Java | JSP | JSF for Vijayadav

Question #282703

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.

1
Expert's answer
2021-12-26T09:41:31-0500

a)

  • Compilation
  • Initialization
  • Execution
  • Cleanup

(https://www.tutorialspoint.com/jsp/jsp_life_cycle.htm)


b)

  • JSP directives are the messages to JSP container. They provide global information about an entire JSP page.
  • JSP directives are used to give special instruction to a container for translation of JSP to servlet code.
  • In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.
  • They give instructions to the container on how to handle certain aspects of JSP processing
  • Directives can have many attributes by comma separated as key-value pairs.
  • In JSP, directive is described in <%@ %> tags.

(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>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog