1 jstl
Jstl (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 roles of jstl
Jstl accelerates the development cycle and greatly simplifies the development and maintenance of JSP applications.
1.2 use of jstl
Set 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 Common labels in jstl
Core tag library and international tag (i18n)
1.3.1 core tag Library
The core tag library mainly includes general-purpose tags, condition tags, iteration tags, and URL-related tags. To 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" prefix =" C "%>
The <C: Out> function is similar to the <% = expression %> in JSP. It is used for page output. The 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 property 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>
. <C: Set> used to set the value of the range variable or the attribute of the JavaBean object. The syntax format is divided into the following five types:
- Specify the variable name and value, and do not specify the scope ). <C: Set Var = "username" value = "value"> </C: Set>
- Store the value in a variable with the 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>
- Store the value in the attributes of the targer object. <C: Set Value = "value" target = "target" property = "propertyname"> </C: Set>
- Store the data in the body content to the attributes of the targer object. <C: set target = "target" property = "propertyname"> body content </C: Set
<C: Remove> remove a variable from 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 and is used to specify the range of the variable to be deleted, the default value is page.
<C: If> labels are used to execute process control. They have the same functions as if 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.
- Choose, when, and otherwise labels
<C: If> A tag can be used to determine only one expression, and cannot be used to 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: oherwise>
</C: Choose>
<C: foreach> two syntax formats: Label. 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>
<C: fortokens> is used to split a string based on the specified delimiter. 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 attributes of "Var", "varstatus", "begin", "end", and "Step" 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.
<C: Import> other static or dynamic files can be included in the JSP page. 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>
<C: param> A tag is used to pass a parameter. 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" %>
<FMT: formatnumber> the number is formatted as 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. The format is as follows:
<FMT: formatnumber value = "Number" [type = {number | Currency | percent}]
[Pattern = "pattern"]
[Currencycode = "currencycode"]
[Currencysymbol = "currencysymbol"]
[Groupingused = "{true | false}"]
[Maxintegerdigits = "maxintegerdigits"]
[Minintegerdigits = "minintegerdigits"]
[Maxfractiondigits = "maxfractiondigits"]
[Minfractiondigits = "minfractiondigits"]
[Var = "varname"]
[Scope = "{page | request | session | application}"]
/>
<FMT: parsenumber> converts a string-type number, currency, or percentage to a number. 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. The format is as follows:
<FMT: parsenumber value = "numberstring" [type = {number | Currency | percent}]
[Pattern = "pattern"]
[Parselocale = "parselocale"]
[Integeronly = "{false | true}"]
[Var = "varname"]
[Scope = "{page | request | session | application}"]
/>
<FMT: formatdate> the date or time is formatted based on the region or custom method to convert the date type into a string 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 }"
]/>
<FMT: parsedate> is used to convert a string-type time or date to a datetime 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. The format is as follows:
<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}"]
/>
<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}"]/>
<FMT: timezone> is used to set the time zone temporarily. The syntax format is as follows:
<FMT: timezone value = "timezone"> body content </FMT: settimezones>
<FMT: setlocale> label is used to set the regional language of a 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 ". The syntax format of <FMT: setlocale> is as follows:
<FMT: setlocale value = "locale" [Variant = "variant"] [scope = "{page | request | session | application}"]/>
<FMT: requestencoding> is used to set the encoding format of the accepted string, which is the same as request. setcharacterencoding. The syntax format of <FMT: requestencoding> is as follows:
<FMT: requestencoding value = "charsename"/>
<FMT: setbundle> is used to set the default data source. It can also be stored in a certain range for use as needed. The syntax format of <FMT: setbundle> is as follows:
<FMT: setbundle basename = "basename" [Var = "varname"] [scope = "{page | request | session | application}"]/>
<FMT: Message> 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. The syntax format is as follows:
<FMT: Message key = "messagekey" [bundle = "resourcebundle"] [Var = "varname"] [scope = "{page | request | session | application}"]/>
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"/>
Body content, <FMT: Param value = "messageparameter"> parameter value </FMT: param>
<FMT: bundle> is also used to set the data source. However, unlike <FMT: setbundle>, <FMT: bundle> sets 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: bundle>
The 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 pojo
Pojo: A simple Java object of pojo (plain old Java objects), which is actually a common JavaBeans. It is short for avoiding confusion with EJB.
The pojo name is used to avoid confusion with ejbs, and its abbreviation is direct. 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 MVC
The full name of MVC is Model View Controller, short for Model-View-controller. It is a model of software design, it is used to organize code by separating business logic from data display.
3.2 role of MVC
MVC is a framework model that forcibly separates application input, processing, and output to facilitate development and maintenance.
Exchange to explore my Sina Weibo: http://weibo.com/tianrui1990