HTML tags in the Struts tag library

Source: Internet
Author: User
Tags html form html page html tags locale reserved tld

An HTML tag in the Struts tag library

HTML tag libraries are primarily used to display HTML elements, and if you do not use this method, you must specify them with HTML tags. On the surface, this tag library is very simple. But by delving into it, we find it very powerful. For example, it can be for us in the HTML form of the

Place the focus content in a particular INPUT element to generate JavaScript, or validate the build script for the client input. Also, you can use it to handle errors in one line of code. However, before you use this tag library for your struts application, you need to do some simple work.

Configure your 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), telling 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>

2. 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 designator:

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

< html:html> label

The < html:html> tag is the easiest tab in the HTML tag library. It has two attributes: Locale and XHTML, both of which are not 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 property in is converted to the generated HTML page. Health

The result depends on the locale of the server on which the struts application resides. If you deploy your application to a different locale server, you don't need to change the code. Locale will automatically adjust.

< html:base> label

The < html:base> tab displays an HTML element that represents the absolute position of the included JSP page with an href attribute. Only when this

The label is embedded in a Head label section and it works. e.g. Helloworld-base:

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

< html:base>< /html:base>



Hello World!
< /html:html>

< html:base> tags will be converted to:

< BASE href= "

< html:link> label

The < html:link> tag generates a hyperlink.

e.g. < Html:link page= "/index.jsp" >Index

will be converted to: Index

< html:errors> label

The ease of use of < html:errors> tags often obscures their true power. With a simple < html:errors>

If the appropriate information exists in the application resources, you can use the following optional message keys:

Errors.header: The corresponding information is displayed before 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 before a separate list of error messages.

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

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.