JavaEE - JSP tags

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

JSP tags

JSTL: A set of tag libraries developed by java itself, which can be used in JSP pages for you to simplify and beautify the code of JSP pages. It also has various statements such as loop, judgment, and ternary, which are mixed with el expressions. Generally, after we use jstl and el expressions, we can't see the java code on the jsp page.

If you want to use the jstl tag library, you have to check whether there are jstl packages in the packages that maven depends on:

If you don't have the jstl package, you have to import it yourself:

First go to the maven central library to bring in the dependencies of jstl;

image

If the import fails, then I will put the downloaded package into the lib under WEB-INF, and then addtobuild,

Then if you want to use the jstl tag library in the jsp page, first import the jstl tag library with the taglib command:

image

Jstl tag library learning:

1. Expression tags: out, set, remove, catch

2. Process markers: if (no else, single-way), choose (multi-way-when, otherwise)

3. Loop tokens: forEach, forTokens

Set tag:

image

image

image

image

You can also assign values ​​to properties in an object:

image

image

image

image

If you use the el expression to output directly, there is no way to filter out the html code:

If you use out to output, it can be filtered, it will filter the html code into entities:

image

image

Of course, the above is the filtering effect of out output. If you don't want to filter, you can use escapeXml to set it to false for filtering:

image

image

You can also output default values ​​for some properties that don't have them (the same effect can be achieved with ternary):

image

image

image

image

This remove can be used to delete stored property values.

image

image

Catch can be used to capture exception information, and then print out exception error information later.

image

image

The single-way condition if judgment is as shown above.

There are also multiple conditional judgments:

image

image

image

image

image

image

image

image

Multi-way conditional judgment, during which you can also use the if statement to make conditional judgments.

Use jstl and el expressions to change the index.jsp page:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326496578&siteId=291194637