JSTL, POJO, and MVC in JSP

Source: Internet
Author: User

1 JSTLJSTL (JSP Standard Tag Library, JSP Standard Tag Library) is a continuously improved open-source JSP Tag Library maintained by the apache jakarta team. 1.1 JSTL helps accelerate the development cycle and greatly simplifies the development and maintenance of JSP applications. 1.2 use JSTL to convert jstl. jar and standard. put the jar file in classpath. If you still need to use the XML processing and Database access (SQL) Labels, you also need to put the relevant JAR files in classpath, add <% @ taglib prefix = "... "uri = "... "%>, then you can use the introduced tag on this JSP page. 1.3 JSTL common tag Core tag library and international tag (I18N) 1.3.1 Core tag library mainly include general-purpose tags, condition tags, iterative tags, and URL-related tags. Use the Core tag on the JSP page. Use the taglig command to specify the referenced tag library, as shown below: <% @ taglib uri =" http://java.sun.com/jsp/jstl/core The "prefix =" c "%> out tag <c: out> function is similar to the <% = expression %> in JSP and is used for page output. Its Syntax format is divided into the following five types: specify the value to be displayed by specifying the value Attribute in <c: out>. <C: out value = "value"/> use the escapeXml attribute to set whether to output the content in the value as is. Because <c: out> converts <,>, ', ", & to <,>,',", and & by default &. If you do not want to convert, you only need to set the escapeXml attribute to "false ". <C: out value = "value" escapeXml = "true | false"/> use the default attribute to specify the default value. If the value is null, the default value is displayed. <C: out value = "value" default = "No data"/> specify the default value through the body content. If the value is null, the default value is displayed. <C: out value = "value" escapeXml = "true | false"/> body content </c: out> set tag. <c: set> used to set the value of a range variable or the attribute of a javabean object. The syntax format is as follows: Specify the variable name and value, without specifying the scope ). <C: set var = "username" value = "value"> </c: set> stores the value in a variable with a scope. <C: set var = "username" value = "value" scope = "page | request | session | application"> </c: set> store the data in the body content to a variable with the scope. <C: set var = "varname" scope = "page | request | session | application"> body content </c: set> stores the value in the attributes of the targer object. <C: set value = "value" target = "target" property = "propertyName"> </c: set> stores the data in the body content to the attributes of the targer object. <C: set target = "target" property = "propertyName"> the body content </c: setremove tag <c: remove> is used to remove variables within a specified range. The syntax format is as follows: <c: remove var = "number" scope = "session">. The var attribute specifies the name of the variable to be deleted. The scope attribute is optional, used to specify the range for deleting variables. The default value is page. The if label <c: if> label is used to execute Process Control. Its function is the same as that in Java. <C: if> A tag has two syntax formats: No ontology content and no ontology content. The <c: if> label format without the body content is as follows. <C: if test = "testCondition" var = "varName" [scope = "{page | request | session | application}]"/> where the test attribute is required, indicates the expression used for judgment. The property var defines a variable that stores the result after judgment. Scope indicates that var defines the range of variable storage. The <c: if> label format with ontology content is as follows. <C: if test = "testCondition" var = "varName" [scope = "{page | request | session | application}]"> body content </if> where the test attribute is required, if the expression in test is true, the body content is executed. If the expression is false, the body content is not executed. The choose, when, and otherwise labels <c: if> can only judge one expression, and cannot specify the statement to be executed if the expression is not true. JSTL also provides the statement <c: choose> label similar to if... else. <C: choose> can contain one or more <c: when> labels with zero or more <c: otherwise> labels. The syntax format is as follows: <c: choose> <c: when test = "testCondition"> </c: when>... <c: oherwise> </c: choose> forEach tag <c: forEach> two syntax formats. One is used to traverse the members of the Set object, and the other is used to make the statements run cyclically for a specified number of times. <C: forEach> traverses the members of the Set object. The syntax format is as follows: <c: forEach [var = "varname"] items = "collection" [varStatus = "varStatusName"] [begin = "begin"] [end = "end"] [step = "step" ]> local content </forEach>, "var" is used to store the specified members; "items" refers to the set object to be iterated; "varStatus" is used to store the information of the specified members; "begin" indicates the start position (0 by default); "end" indicates the end position. "Step" indicates the step size (1 by default ). <C: forEach> specifies the number of statement executions. The syntax format is as follows: <c: forEach [var = "varname"] [varStatus = "varStatusName"] [begin = "begin"] [end = "end"] [step = "step"]> local content </forEach> forTokens tag <c: forTokens> is used to separate strings based on specified delimiters. The syntax format is as follows: <c: forTokens [var = "varname"] items = "stringOfTokens" delims = "delimiters" [varStatus = "varStatusName"] [begin = "begin"] [end = "end"] [step = "step"]> local content </c: forTokens> the "var", "varStatus", "begin", "end", and "step" attributes are the same as those in the <c: forEach> label. The "items" attribute indicates the split string, and the "delims" attribute specifies the separator. <C: forTokens> you can separate strings with only one separator, or separate strings with multiple delimiters by setting multiple delimiters, you only need to set multiple delimiters. The import tag <c: import> can include other static or dynamic files to its own JSP webpage. The biggest difference between it and the JSP Action Command <jsp: include> is that <jsp: include> can only contain files in the same Web application as itself; and <c: import> In addition to files that can contain the same Web application as your own, you can also contain files of different Web applications or other websites. <C: import> syntax format: <c: import url = "url" [context = "context"] [var = "varName"] [scope = "{page | request | session | application}"] [charEncoding = "charEncoding "]> body content </c: import> or <c: import url = "url" [context = "context"] varReader = "varReaderName" [charEncoding = "charEncoding"]> body content </c: import> param label <c: param> label is used to pass parameters. It contains two parameters: name and value. <C: param> syntax format: <c: param name = "parameter name" value = "parameter value"> 1.3.2 International tag (I18N) to use the format tag on the JSP page, you must use the <% @ taglib %> command to specify the format tag. The Code is as follows: <% @ taglib prefix = "fmt" uri =" http://java.sun.com/jsp/jstl/fmt "%> The formatNumber label <fmt: formatNumber> Format the number to a number, currency, or percentage based on the region or custom method. There are two types of syntax: one is to use the value attribute to specify the number to be formatted without the body content; the other is to use the body content to specify the number to be formatted. Format: <fmt: formatNumber value = "number" [type = {number | currency | percent}] [pattern = "pattern"] [currencyCode = "currencyCode"] [currencySymbol = "currencySymbol"] [groupingUsed = "{true | false}"] [maxIntegerDigits = "maxIntegerDigits"] [numbers = "minIntegerDigits"] [maxFractionDigits = "maxFractionDigits"] [minFractionDigits = "minFractionDigits"] [var = ""varName"] [scope = "{page | request | sessi On | application} "]/> parseNumber label <fmt: parseNumber> is used to convert a string-type number, currency, or percentage to a numeric type. This is the opposite of the <fmt: formatNumber> label. There are two types of syntax: one is no ontology content, and the value attribute is used to specify the string to be converted to a number; the other is body content, use the body content to specify the string to be converted to a number. Format: <fmt: parseNumber value = "numberString" [type = {number | currency | percent}] [pattern = "pattern"] [parseLocale = "parseLocale"] [integerOnly = "{false | true} "] [var =" varName "] [scope =" {page | request | session | application} "]/> formatDate tag <fmt: formatDate> Format the date or time according to the region or custom method to convert the date type to the string type date. The syntax format is as follows: <fmt: formatDate value = "number" [type = {time | date | both}] [pattern = "pattern"] [dateStyle = "{default | short | medium | long | full }"] [timeStyle = "{default | short | medium | long | full}"] [timeZone = "timeZone"] [var = "varName"] [scope = "{page | request | session | application} "]/> parseDate tag <fmt: parseDate> is used to convert the time or date of the string type to the date and time type. This is the opposite of the <fmt: formatDate> label. There are two types of syntax: one is no ontology content, and the value attribute is used to specify the string to be converted to the date and time; the other is the ontology content, use the body content to specify the string converted to the date and time. Format: <fmt: parseDate value = "date" [type = {time | date | both}] [pattern = "pattern"] [dateStyle = "{default | short | medium | long | full }"] [timeStyle = "{default | short | medium | long | full}"] [timeZone = "timeZone"] [var = "varName"] [scope = "{page | request | session | application} "]/> setTimeZone tag <fmt: setTimeZone> is used to set the default time zone or store the time zone in the attribute range. The syntax format is as follows: <fmt: setTimeZone value = "timeZone" [var = "varName"] [scope = "{page | request | session | application}"]/> timeZone tag <fmt: timeZone> is used to temporarily set the time zone. The syntax format is as follows: <fmt: timeZone value = "timeZone"> body content </fmt: setTimeZones> setLocale tag <fmt: setLocale> label is used to set the regional language of the user. The regional language here refers to the language type used by the user's region and the synthesis of the country and region. For example, the Chinese language is used in mainland China, the language code is "zh", and the region code is "cn". Therefore, the language region in mainland China is "zh_cn ". <Fmt: setLocale> syntax format: <fmt: setLocale value = "locale" [variant = "variant"] [scope = "{page | request | session | application}"]/> requestEncoding tag <fmt: requestEncoding> is used to set the encoding format of the accepted string, and request. the setCharacterEncoding () function is the same. <Fmt: requestEncoding> syntax format: <fmt: requestEncoding value = "charseName"/> setBundle tag <fmt: setBundle> is used to set the default data source, it can also be stored in a certain range for use as needed. <Fmt: setBundle> syntax format: <fmt: setBundle basename = "basename" [var = "varName"] [scope = "{page | request | session | application}"]/> message tag <fmt: message> is used to obtain the value from the specified resource file through the index (key ). The syntax is divided into two types: No ontology content, key attribute is used to specify the index, and ontology content is used to specify the index. Syntax format: <fmt: message key = "messageKey" [bundle = "resourceBundle"] [var = "varName"] [scope = "{page | request | session | application}"]/> param label when when obtaining information from the resource file, you may need to set parameters dynamically, such as the user name. <Fmt: param> is used to pass the parameter. The syntax is divided into two types: one is to use the value attribute to specify the parameter value without the body content; the other is to use the body content to specify the parameter value. The syntax format is as follows: no body content. <fmt: param value = "messageParameter"/> the body content is available. <fmt: param value = "messageParameter"> parameter value </fmt: param> bundle label <fmt: bundle> is also used to set the data source, but unlike <fmt: setBundle>, <fmt: bundle> set the data source to be valid only for tags in the body content. The syntax format is as follows: <fmt: bundle basename = "basename" [prefix = "prefix"]> body content {<fmt: message >}</fmt: the bundle> message <fmt: setLocale> label is used to set the regional language of the user. The regional language here refers to the language type used by the user's region and the synthesis of the country and region. For example, the Chinese language is used in mainland China, the language code is "zh", and the region code is "cn". Therefore, the language region in mainland China is "zh_cn ". <Fmt: setLocale> syntax format. <Fmt: setLocale value = "locale" [variant = "variant"] [scope = "{page | request | session | application}"]/> timeZoneformatDateparseNumberformatNumber 2 POJOPOJO: POJO (Plain Old Java Objects) is a simple Java object, which is actually a common JavaBeans. It is short for avoiding confusion with EJB. Www.2cto.com uses the POJO name to avoid confusion with ejbs. some attributes and Their getter setter methods have no business logic. They can be used as VO (value-object) or dto (Data Transform Object. of course, if you have a simple operation attribute, you can do the same, but you cannot have business methods or methods such as connection. POJO can be essentially understood as a simple entity class. As the name suggests, POJO classes are used to facilitate programmers to use data tables in databases, POJO classes can be conveniently used as objects, and the get and set methods can also be conveniently called. 3 MVC3.1 what is MVCMVC? The full name is Model View Controller. It is short for model-view-controller. It is a software design Model, it is used to organize code by separating business logic from data display. 3.2 The role of MVC is a framework model that forcibly separates application input, processing, and output for development and maintenance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.