Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the purpose of the HTML tag in the Struts tag library

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what is the role of Struts tags in the HTML tag library". In daily operation, I believe many people have doubts about the role of HTML tags in the Struts tag library. The editor consulted all kinds of information and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what is the role of HTML tags in the Struts tag library". Next, please follow the editor to study!

one。 HTML tags in the Struts tag Library

The HTML tag library is mainly used to display HTML elements, and if you don't use this method, you have to specify them with the HTML tag. On the face of it, this tag library is simple. But through in-depth study, we will find that it is very powerful. For example, it can be used for our HTML form

Place highlights in a specific input element to generate a JavaScript, or generate a script for client input validation. Also, you can use it to handle errors with a single line of code. However, you need to do some simple preparation before using this tag library for your Struts application.

Configure the application to use the tag library

Before using the Struts HTML tag library, you need to configure a Struts application in three steps.

1. Register the tag library in the deployment descriptor (web.xml file) and tell the servlet container about the Struts HTML tag library and where to find the TLD file for the tag library, as follows:

/ WEB-INF/struts-html.tld

< /TAGLIB-URI>

/ WEB-INF/struts-html.tld

< /TAGLIB-LOCATION>

two。 Be sure to copy the struts-html.tld file to the WEB-INF directory. You don't have to worry about tag library class files because they are already included in the struts.jar file.

3. In each JSP page that uses the tag library, insert the following indicator:

The HTML tag library contains several separate tags that are easy to use:

< html:html>

Label

< html:html>

Tags are the easiest tags in the HTML tag library. It has two properties: locale and xhtml, neither of which is required.

E.g. HelloWorld-html:

Create a JSP page welcome.jsp and enter the following:

< %@ taglib uri="/WEB-INF/struts- html.tld" prefix="html" %>

< ?xml:namespace prefix = html />

< html:html locale="true">

Hello World!

The locale attribute in the generated HTML page is converted to. Unripe

The result depends on the locale of the server where the Struts application is located. If you deploy the application to a different locale server, you don't need to change the code. Locale adjusts automatically.

< html:base>

Label

< html:base>

The tag displays a HTML element with a href attribute indicating the absolute position of the included JSP page. Only when this

A tag is valid only if it is embedded in an head tag section. E.g. HelloWorld-base:

< %@ taglib uri="/WEB-INF/struts- html.tld" prefix="html" %>

< html:base>

< /html:base>

Hello World!

< /html:html>

< html:base>

The label is converted to:

< BASE href=" < html:link>

Label

< html:link>

The tag generates a hyperlink.

E.g.

< html:link page="/index.jsp">

Index

< /html:link>

Will be converted to: Index

< html:errors>

Label

< html:errors>

The ease of use of tags usually obscures its true power. Through a simple

< html:errors>

< /html:errors>

Tag, you can display completely customized error messages on a JSP page. This tag examines the property collection of the Request object to find a reserved key. If it finds a reserved key, it assumes that the key is a String, or an array of String (which contains the message keys found in the module's MessageResources), or an object of type org.apache.struts.action.ActionErrors.

If the appropriate information exists in the application resource, the following optional message keys can be used:

Errors.header: the corresponding information is displayed in front of a separate list of error messages.

Errors.footer: the corresponding information is displayed after a separate list of error messages.

Errors.prefix: the corresponding information is displayed in front of a separate list of error messages.

Errors.suffix: the corresponding information is displayed after a separate list of error messages.

two。 Logic tag

1. Define the label file (web.xml)

/ tags/struts-logic

/ WEB-INF/struts-logic.tld

2. Reference tag file (jsp file)

3. Label file description (struts-logic.tld)

(1) empty tag

Class name: org.apache.struts.taglib.logic.EmptyTag

Tag body: bodycontent=JSP

Quote logic:empty

Property attribute:name,property,scope

Function: determine whether the value of the object is empty

(2) equal

Class name: org.apache.struts.taglib.logic.EqualTag

Tag body: bodycontent=JSP

Quote logic:equal

Property attribute:cookie,header,name,parameter,property,scope,value

Function: equal to comparison character

(3) forward

Org.apache.struts.taglib.logic.ForwardTag

Tag body: bodycontent=empty

Quote logic:forward

Property attribute:name

Function: page oriented to find the global forward of the configuration file

(4) greaterEqual

Class name: org.apache.struts.taglib.logic.GreaterEqualTag

Tag body: bodycontent=JSP

Quote logic:greaterEqual

Property attribute:cookie,header,name,parameter,property,scope,value

Function: greater than or equal to comparison character

(5) greaterThan

Class name: org.apache.struts.taglib.logic.GreaterThanTag

Tag body: bodycontent=JSP

Quote logic:greaterThan

Property attribute:cookie,header,name,parameter,property,scope,value

Function: greater than the comparator

(6) iterator

Class name: org.apache.struts.taglib.logic.IterateTag

Tag body: bodycontent=JSP

Quote logic:iterator

Property attribute:collection,id,indexId,length,name,offset,property,scope,type

Function: display values whose list is collection (List, ArrayList,HashMap, etc.)

(7) lessEqual

Class name org.apache.struts.taglib.logic.LessEqualTag

Tag body: bodycontent=JSP

Logic:lessEqual

Property attribute:cookie,header,name,parameter,property,scope,value

Function: less than or equal to comparison character

(8) lessThan

Class name: org.apache.struts.taglib.logic.LessThanTag

Tag body: bodycontent=JSP

Logic:lessThan

Property attribute:cookie,header,name,parameter,property,scope,value

Function: less than the comparator

(9) match

Class name: org.apache.struts.taglib.logic.MatchTag

Tag body: bodycontent=JSP

Quote logic:match

Property attribute:cookie,header,location,name,parameter,property,scope,value

Function: compare object

(10) messagesNotPresent

Class name: org.apache.struts.taglib.logic.MessagesNotPresentTag

Tag: bodycontent=JSP

Quote logic:messagesNotPresent

Property attribute:name,property,message

Function: whether the ActionMessages/ActionErrors object does not exist

(11) messagePresent

Class name: org.apache.struts.taglib.logic.MessagesPresentTag

Tag: bodycontent=JSP

Quote logic:messagePresent

Property attribute:name,property,message

Function: whether the ActionMessages/ActionErrors object does not exist

(12) notEmpty

Class name: org.apache.struts.taglib.logic.NotEmptyTag

Tag: bodycontent=JSP

Quote logic:notEmpty

Property attribute:name,property,scope

Function: compare whether the object is not empty

(13) notEqual

Class name: org.apache.struts.taglib.logic.NotEqualTag

Tag: bodycontent=JSP

Quote logic:notEqual

Property attribute:cookie,header,name,parameter,property,scope,value

(14) notMatch

Class name: org.apache.struts.taglib.logic.NotMatchTag

Tag: bodycontent=JSP

Quote logic:notMatch

Property attribute:cookie,header,location,name,parameter,property,scope,value

Function: compare whether objects are not equal

(15) notPresent

Class name: org.apache.struts.taglib.logic.NotPresentTag

Tag: bodycontent=JSP

Quote logic:notPresent

Property attribute:cookie,header,name,parameter,property,role,scope,user

Function: whether the parameter passed by the request object does not exist

(16) present

Class name: org.apache.struts.taglib.logic.PresentTag

Tag: bodycontent=JSP

Quote logic:present

Property attribute:cookie,header,name,parameter,property,role,scope,user

Function: whether the parameters passed by request object exist

(17) redirect

Class name: org.apache.struts.taglib.logic.RedirectTag

Tag: bodycontent=JSP

Quote logic:redirect

Attribute

Attribute:anchor,forward,href,name,page,paramId,paramName,paramProperty,paramScope,property

Scope,transaction

Function; page redirection, transferable parameters

At this point, the study on "what is the role of Struts tags in HTML tag library" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report