What is the purpose of the <jsp:include> tag in JSP?

Java MCQ: What is the purpose of the <jsp:include> tag in JSP?

a) To declare a variable
b) To include another JSP file at runtime
c) To create a comment
d) To forward a request to another resource

Answer:

b) To include another JSP file at runtime

Explanation:

The <jsp:include> tag in JSP is used to include another JSP file or static resource at runtime. Unlike the include directive, which includes content at compile time, the <jsp:include> tag includes the content dynamically during request processing, allowing the included resource to be processed independently.

Here’s an example:

<jsp:include page="header.jsp" />

In this example, the content of header.jsp is included in the main JSP page when the request is processed.

The <jsp:include> tag is useful for including dynamic content, such as headers, footers, or reusable components, that may change based on the context of the request.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top