Strut1.x and JSTL label library, EL expression, strut1.xjstl

Source: Internet
Author: User
Tags tld

Strut1.x and JSTL label library, EL expression, strut1.xjstl
Struts tag Library
International Configuration

 

Configure Internationalization

 

1. International Configuration


Adding <message-resources parameter = "MessageResources"/> In the struts-config.xml In the struts-embedded app to the configuration file in the project defaults to a struts-config.xml.

 

2. Import International files


MessageResources. properties (located in \ struts-1.3.10 \ src \ apps \ blank \ src \ main \ java \ MessageResources. properties), and put the file under src of the project file

 

Add the jsp File Header


<% @ Taglib uri = "http://struts.apache.org/tags-bean" prefix = "bean" %>

 

Syntax

Hello Tag: <bean: write name = "hello"/>

 

This will display the information set in the request.

 

Java

Request. setAttribute ("hello", "cfltaglib ");

 

Category

 

In struts1.3, taglib is divided into: bean htmllogic nested

 

The usage and definition of each tag are described in the corresponding dtld file. What is a tld file? Open the file and you can see that some xml configurations record the tag.


For example:


Version Number <tlib-version> 1.3 </tlib-version>


Jsp version <jsp-version> 1.2 </jsp-version>


We recommend that you use the prefix name. Of course, you do not need to use the recommended prefix. to unify the standard and Development convenience, it is best to be consistent with the suggestions or the entire project development team.

<Short-name> bean </short-name>

Uri resource location file address <uri> http://struts.apache.org/tags-bean </uri>

This is used to access the resource address stored on the struts Service server. This address is the resource location address of tags-bean. Of course, it is different from the url we usually use.

The root directory of tld is taglib, which is used to define the description of the corresponding tag and put it in the tag Element of the child element. The corresponding examples and instructions are provided.


Bean

 

It is used to access some data defined in the javabean, while the search is based on the name in the tag, and the search order is based on the range set in the set scope. If no specific range is set for the tag, the search order is page, request, session, and application. In addition, the third-party tag is also used to search for and display and process data.

 

1. output text


<Bean: write name = "hello"/>


2. format the date


<Bean: write name = "propertyname" format = "yyyy-mm-dd"/>


3. Output javabean Object Attributes


<Bean: write name = "beanname" property = "property"/>

Name: A javabean object.

Property: Provides get and set attributes for javabean.


Logic

 

Execution logic judgment: The logic judgment here is limited to the logic judgment used for data display, which is different from the logic processing about the business. Labels focus on data display.


 

Introduce <% @ taglib uri = "http://struts.apache.org/tags-logic" prefix = "bean" %>


1. empty or not


<Logic: empty name = "hello"> if it is null, enter here for judgment </logic: empty> <logic: empty name = "hello"> if it is not empty, enter here for judgment </logic: empty>


Similarly, logic: present

2. iterator


<logic:iterate name="listname"></logic:iterate>


In fact, the display is mostly consistent. It is nothing more than configuring the corresponding data for the corresponding variables in the javabean in the background.

 

Html

 

It is mainly used to configure the tag library for front-end form display, which is very convenient to use.

For example,

 

More: http://www.360doc.com/content/13/1227/16/1007797_340571617.shtml

 

EL expression

 

In struts1.x, EL expressions are also used for auxiliary work. Similar to the expression structure of scripts, data is directly searched in pages, requests, sessions, and applications, but the difference is that the object type set in javabean is directly returned. Set the data type to be returned. Of course, you can also directly access the attribute data of the object in the javabean.


Syntax:


$ {Name} or $ {javabean. property}


 

It is relatively simple to use, and users do not need to consider the data type for direct use. Struts2 cannot use EL expressions nested due to security issues, but it can still be used in html tags. Struts uses an OGNI expression, a lambda expression, but also compatible with common writing. The subsequent articles will explain the usage.

 

That is, <s: url id = "selectData1" value = "$ {pageContext. request. contextPath} is unavailable, but <span >$ {name} </span> is still usable. You can also enable expressions on the page. ---- <% @ page isELIgnored = "false" %> enable EL expressions. jsp2.0 is enabled by default.

 

El also involves operators and can accomplish the same effect as the struts1.x tag library. For more information, see http://www.blogjava.net/supercrsky/articles/179363.html.

 

JSTL


Jsp standard taglibrary is an ever-evolving open-source tag library, which includes four core fmt SQL tlv Tag libraries.

 

Two jar packages, jstl. jar and standard. jar, must be referenced during use. Iteration and condition judgment, data management formatting, XML operations, and database access. Generally, EL expressions are used together.

 

Environment Configuration


Import the. jar package


Jstl. jar and standard. jar


Import uri resource files


<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "h" %>, here I customize to write h, of course, it is recommended to write c.


Classification Core

 

It is mainly used to display data and can replace the out or <% = %> label to output the object value. Similar to write in struts


Demo

<Li> test the jstl core library </li> <br> <li> normal expression </li> <br> 


Fmt

As its name implies, it is for formatting.


Demo


<Li> test format date </li> <fmt: formatDate value = "$ {riqi}"/> <br> <li> short format date </li> <fmt: formatDate value = "$ {riqi}" dateStyle = "short"/> <li> date in both format </li> <fmt: formatDate value = "$ {riqi}" type = "both"/>


SQL

Operate databases directly on the page. Of course, this situation is rarely used, and it is only applicable to special cases.


Demo


Establish a database connection <SQL: setinclucedriver = "driverClass" url = "jdbcURL" user = "username" password = "pwd" [var = "name"] [scope = "page | request | session | application"] />


 

Descending Order

JSTL, struts labels, and EL expressions are all custom labels, while EL is the servlet standard and is generally compatible. In the beginning, it was used to simplify the page, prevent the emergence of java code on the page. The struts tag machine JSTL requires corresponding jar packages for configuration and corresponding uri for resource introduction. Jstl is a relative standard, and the struts development kit also carries the jstl jar package. The query documents show that the performance of struts labels is almost the same as that of jstl. I have not practiced it yet and have no experience yet. In general, it is a type of tag library. Specific use, personal habits combined with project standards.

 

 

 

 

 

 


Can EL expressions and JSTL label libraries be nested in div?

Show $ {sessionScope. userId} between two output tags.
 
Q: What are EL expressions, ognl expressions, and jstl expressions, and their relationships and differences?

Both el and ognl are expressions in different languages, but their syntax is different. The so-called expression language is to input a string of expressions. The interpreter can help you evaluate the value. Jstl is a set of tag libraries. To put it bluntly, it is a set of tags that can be used on jsp pages. Both jstl and el are part of jsr. Ognl is a set of expressions in the community. It was originally used for webwork.
 

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.