Trending October 2023 # Various Directives In Jsp You Need To Know # Suggested November 2023 # Top 18 Popular |

Trending October 2023 # Various Directives In Jsp You Need To Know # Suggested November 2023 # Top 18 Popular

You are reading the article Various Directives In Jsp You Need To Know updated in October 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 Various Directives In Jsp You Need To Know

Overview of JSP Directives

JSP pages contain directives that direct the container about the processing of the page; these directives are associated with the compiled servlet that is automatically created by the JSP page. While the directives give processing instructions to the container running the component, the directive does not create any output.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Standard Syntax for the directive is as follows:

JSP contains three directives:

Page Directive: To configure page level settings, example – import – “java.util.*”

Include Directive: To include a file, example – file=” Header.JSP”

Taglib Directive: Contains custom actions that can be used on the page.


Various JSP Directives

JSP directives are components of a JSP source code that guide the web container on how to convert the JSP page into its corresponding servlet. Let’s look at a few directives.

1. Page Directive

The page directive is used to instruct the JSP translator about certain aspects of the current JSP page, like the content type to be used, like language in which page has to be written, etc.

The page directive has the following syntax:


Now let’s define a list of attributes used for the page directive:

a. Import: It is used to declare the java types to be used on the current page. Like if we want to use lists in the JSP page and iterate over them, then we can import java.util.list, likewise other common packages like IO, util, etc., can be imported in likewise way. There are certain implicit imports done, which we need not declare while working with the JSP pages and servlets in JSP Directives which are as follows:




c. Buffer: It tells the buffer size of out implicit object in kb; it is necessary to mention kb at the end of mentioned buffer size, the default value is 8kb or more depending on the JSP container; if this is set to none, then it will cause the output to be written directly to the corresponding PrintWriter.

d. AutoFlush: The default value is true; this indicates that the buffer value shall be auto flushed when the buffer is full. A value of false indicates that the buffer is only flushed if the flush method of the response implicit object is called.

e. IsThreadSafe: It is a deprecated practice, not generally used, indicates the thread-safety implemented in the page.

f. Info: GetServletInfo method’s return value is specified here.

g. Errorpage: Incorporated for page error handling.

i. ContentType: Whenever you send the data to the controller at the backend, the body has an associated content type, like if you send JSON, XML, the plain text, then the container will get aware of a content type that it shall respond with. The response object will be created likewise.

j. Page Encoding: Default, the value is ISO-8859-1, indicates the character encoding.

k. Language: Used to tell the scripting language used in a page, a default value will be java only.

l. Extends: Used to inherit the superclass like base layout can be inherited in all pages.

m. Trim Directive Whitespaces: Whether the template text has whitespaces or not, the default is false.

2. Include Directive


You can import the header .jsp, chúng tôi chúng tôi into all other pages and just you need to give the content to be rendered into the current page with the specific details adhering to the current page only.

The syntax for such inclusion is:

Please note that the merging of included files happens at the translation time only and not at request time, i.e.

None of the included JSP code is executed; it is not even compiled yet.

The files are first merged, and then the entire merged output is translated as a unit.

If the included files are ever changed, there is no general way for the container to know and recompile the entire translation unit.

3. Taglib Directive

It is used to tell the container which tag library a specific JSP requires. It is also used to assign a prefix that is used within the JSP page to identify tags from a specific tag library. Container, when it gets these taglibs, it locates the code for those taglibs and makes them ready to use JSP.

Syntax to use the taglib is as follows:


So this makes an indication to the container that these all tags are used from this tag library and will be prefixed with the c: namespace within this JSP Directives. This URI can be associated with a tag library through a TLD file. The TLD can be mapped using a taglib map in the chúng tôi file or via specific placement under the META-INF directory within a JAR archive.

The tag directory can also be specified as:


So you can place tag flies at WEB-INF/tags, and the container will get it from there.


Hence we have seen JSP Directives and what indications do the above-mentioned directives actually give to the container and how the container keeps things resolved at the time of usage, these directives are used to add dynamic behaviour, and whenever dynamic web projects are designed, these approaches come worthy. Likewise, the approach has been used in other synonymous frameworks like struts, and many URL’s are available there for such usage.

Recommended Articles

This has been a guide to JSP Directives. Here we discuss the basic concept, various directives, with their explanation and examples. You can also go through our other suggested articles to learn more –

You're reading Various Directives In Jsp You Need To Know

Update the detailed information about Various Directives In Jsp You Need To Know on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!