Important Web Design and Development Short Questions
Chapter: 37
Question 1:
What is the function of the <jsp:getProperty /> action element?
Answer:
The <jsp:getProperty /> action element retrieves the value of a specified property from a JavaBean and writes it to the output stream. The name attribute specifies the bean, and the property attribute specifies which property to retrieve.
Chapter: 37
Question 2:
What are the different scopes for JavaBeans in JSP?
Answer:
JavaBeans in JSP can be stored in four scopes: page, request, session, and application. Page scope limits the bean's availability to the page where it is created. Request scope allows the bean to be available across pages during a single request. Session scope keeps the bean available throughout a user's session. Application scope makes the bean available across all JSPs and servlets in the web application.
Chapter: 37
Question 3:
How does the <jsp:include /> action element differ from the <jsp:forward /> action element?
Answer:
The <jsp:include /> action element includes the content of another file at request time, allowing for content reuse and updates without affecting the main page. The <jsp:forward /> action element forwards the request to another resource, transferring control and allowing the target resource to process the request.
Chapter: 37
Question 4:
What is the purpose of the scope attribute in the <jsp:useBean /> action element?
Answer:
The scope attribute in the <jsp:useBean /> action element determines where the JavaBean object is stored and how long it will be available. It can be set to page, request, session, or application, affecting the bean's visibility and lifecycle.
Chapter: 37
Question 5:
Explain the difference between page and application scope for JavaBeans.
Answer:
page scope restricts the bean's visibility to the page where it was created, while application scope makes the bean available to all JSPs and servlets within the same web application, sharing the bean across all users and sessions.
Chapter: 37
Question 6:
How does the <jsp:plugin /> action element work?
Answer:
The <jsp:plugin /> action element is used to work with applets by generating HTML code for embedding applets within a JSP page. It allows for the inclusion of applet content and configuration within the JSP.
Chapter: 38
Question 7:
What is the main purpose of using custom tags in JSP?
Answer:
Custom tags in JSP are used to encapsulate complex functionality and simplify the JSP code. They allow web designers to include advanced features without needing to write Java code directly in JSP pages. This separation of presentation and business logic makes the code cleaner and easier to manage.
Chapter: 38
Question 8:
Explain the difference between a simple tag and a tag with attributes in JSP.
Answer:
A simple tag in JSP has no attributes or body; it only consists of a start and end tag. For example, <mytag:hello />. In contrast, a tag with attributes includes attributes within the tag, allowing for customization. For instance, <mytag:hello attribute="value" /> has an attribute that can be used to pass data to the tag. Both types of tags simplify JSP development, but tags with attributes offer more flexibility.
Chapter: 38
Question 9:
Describe the steps involved in building a custom tag in JSP.
Answer:
Building a custom tag in JSP involves several steps: 1) Develop the Tag Handler class by implementing the SimpleTag interface or extending SimpleTagSupport and overriding the doTag() method. 2) Write the Tag Library Descriptor (.tld) file to define the tag's attributes and mapping to the Tag Handler class. 3) Deploy the Tag Handler class to the WEB-INF/classes folder and the .tld file to the WEB-INF/tlds folder of the web application.
Chapter: 38
Question 10:
How does the doTag() method function in a custom tag handler?
Answer:
The doTag() method in a custom tag handler is responsible for defining the functionality of the tag. It is invoked when the end tag is encountered. This method can use JSP implicit objects, such as out, to generate content that is inserted into the JSP page. The doTag() method typically performs operations such as writing HTML or processing data based on the tag's attributes and then outputs the result to the JSP page.