all JSP implicit objects. The appearance of tags completely solves this problem, this allows you to compile JSP pages of "pure HTML". The benefits are self-evident: Higher maintainability, higher Component Reuse efficiency, and easier maintenance of HTML pages.
I just started to learn JSTL. I think this stuff is really good! I would like to let more beginners know this and apply it to actual JSP application development.Next, write our first Tag!
** The following is a JSP file using a simple Tag
When we develop custom tags in a Web application, these custom tags usually have the tag processor Java class, and a description of these tag TLD files, if we want to be able to use these tags in other Web projects later, you can encapsulate these custom tags in a jar package, Just like the JSTL tag library.We are now ready to encapsulate the custom tags developed in the Web application into jar packages, which are two files of these custom labels as
JSP tags have the same format as HTML tags, which can be used instead of Java scripts in JSPs to introduce code. Before using a custom label, you need to create a *.tld file, each with a tag library that can contain a lot of custom tags.Each tag must be implemented by an implementation class that inherits the Simpletagsupport class. The properties inside the class must have a get and set method. The Dotag method needs to be rewritten, in effect this m
Examples of custom tag usage in jsp and Analysis of jsp instances
This example describes the use of custom tags in jsp. Share it with you for your reference. The details are as follows:
Here we simply write a custom tag. The advantage of custom tags is that you can use your own defined functions on the jsp page, completely separated from Java code.
1. The tld file is as follows:
First, you need to write the X. tld
defined internally to complete the corresponding functions.
Custom JSP tag Development Process
When using the Java processing class to develop custom JSP labels, there are mainly the following steps.
-Tag Handle Class ). This class implements the Tag interface, which is used to define the behavior of tags and is called and executed when the JSP Engine encounters a custom Tag.
-Create a Tag Library description File (tld) and describe the Tag processor
Custom tags are mainly used to remove java code from Jsp pages.Execution Process of custom JSP labelsWhen a JSP page containing custom tags is translated into Servlet by the JSP Engine (Web Container), the JSP Engine encounters custom tags, this custom tag is converted into a call called "tag processing class. Then, when the JSP page is executed, the JSP Engine will call the "tag processing class" object and execute the corresponding operation methods defined internally to complete the correspon
For versions earlier than javaEE5, You need to reference JSTL-related jar packages and tld files. After JAEE5, you don't have to worry about this. If you still cannot use it, download it from the official website (jstljar and standardjar) these two jar packages put the corresponding tld file under the root directory of the project. For versions earlier than javaEE5, the core must reference the jar packages
.
------ Solution --------------------
Go to IT home at www.goithome.com
------ Solution --------------------
Use apache's virtualhost to implement it. For more information, see the manual.
NameVirtualHost *: 80
ServerName www. domain. tld
ServerAlias domain. tld *. domain. tld
DocumentRoot/www/domain
ServerName www. oth
, ENUM resolution, and DNS configuration.
1. Telephone number preprocessing
The user enters the phone number, for example, "+ 86-27-87694036" and "+", to identify the ENUM service and distinguish other digital-based network services. If the number string entered by the user contains "+ ", the ENUM service preprocessing will be executed.
First, remove the characters except "+" to get "+ 862787694036", then remove "+", and then add ". "to get" 8.6.2.7.8.7.6.9.4.0.3.6 "(the reason why we simply add
One, custom Jstl label1. Write the label Processing class:(1) Implement Simpletag interface, through the Setjspcontext () method can get to Jspcontext object, is actually PageContext object.Complete the logic in the Dotag () method by JspWriter out = Jspcontext.getout (); Gets the out object that can be output to the page. Such as:/*** MyTag2 * *@authorSolverpeng * @create 2016-07-03-10:20*/ Public classMyTag2ImplementsSimpletag {PrivateJspcontext Jspcontext =NULL; @Override Public voidDotag ()t
2. Custom Labels1). HelloWorld①. Create a label processor class: Implement the Simpletag interface.②. In the Web-inf folder, create a new. TLD (Tag library profile) as an XML file with an extension. and copy into the fixed part: and theDescription, Display-name, tlib-version, Short-name, Uri make changesXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptagl
way to ensure that the generated pages are encoded correctly is to pass each character in the dynamic content through an encoding function, in which the scripting tags in the dynamic content are substituted for the code in the selected character set. This task is best suited for custom tag libraries.Basics of customizing the tag libraryA custom tag library consists of one or more Java language classes (called tag handlers) and an XML tag library description file (
Jstl1.2.jar
Today, I encountered an error when using the
Value = "$ {(flist. ADDR-(flist. ADDR % 10)/10}">
The following error is reported during running:
According to TLD or attribute directive in Tag file, attribute value does not accept any expressions.
You can still understand it. The general meaning is that the value attribute cannot accept expressions. Searching for information on the Internet is also confusing, so I ran to the jar
1. Edit D: \ XAMPP \ apache \ conf \ httpd. conf in notepad and add the port to be listened on at the top, for example, 8081. Retain the default listening port 80.
Listen 80
Listen 8081.
2. Add:
Servername localhost // local address. You can try to use 127.0.0.1 or 192.168.1 .**
DocumentRoot D: \ XX // point to your url
Require all granted
3. Restart Apache (XAMPP ).
If you want to add a custom domain name and browse it, follow these steps:
1. Configure the domain name (any): www.a.com,
About web. X, which does not recognize The problem of unrecognized Org. Apache. Jasper. jasperexception: the absolute URI:
Http://java.sun.com/jstl/coreCannot be resolved in either web. xml or the jar files deployed with this application
The labels of my‑s5 can be directly used without declaring the However, on the JSP pageMust be added: Http://java.sun.com/jsp/jstl/core"Prefix =" C "%>,If the tag is not added, the tag is ignored and displayed as blank.If the value is: Http://java.sun.com/jsf/c
eval_body_include.
3. bodytagThe bodytag interface extends the iterationtag and provides the function of operating the code body content. When calculating the code body, you can modify the formed code body. The bodycontent object is used to save the computing results of the custom tag body. It has a new method, doinitbody (), which is called only when the dostarttag () method returns eval_body_buffered. At this time, it creates a bodycontent object to save the result.
Extended custom tags:Add a
clients(Client_id, client_name, client_type)Select 10345, 'ibm ', 'advertising'From dualWhere not exists (select * from clientsWhere clients. client_id = 10345 );
Using Dual as the table name allows you to directly keep up with the values of the fields to be inserted after the SELECT statement, even if these values do not exist in the current table.
Implementation of updating when the insert record exists when the MySQL record does not exist copy Code the code is as follows: mysql> t
The labels provided by jstl are very powerful, but only these labels cannot fully meet the actual development needs. When necessary, we can write our own labels by ourselves, you can even build your own tag library.
To develop a custom tag, you must first develop the class corresponding to the tag, and then write the tag description file TLD, and put this file under the web-info directory (in fact, it can be placed in another directory, but it needs t
or JSP 2.0 simple tag API. By comparing these two APIs, you will find that the new APIs are easier to use. The simple tag API has only one interface (javax. servlet. jsp. tagext. SimpleTag), which defines the methods for processing custom tags. These methods are usually called from the Java Servlet automatically generated by the JSP Container from the JSP page.
The javax. servlet. jsp. tagext. SimpleTagSupport class implements the SimpleTag interface. Therefore, when the tag processing class ex
;
Publicclass simpletagdemo extends simpletagsupport {
@ Override
Public void dotag () throws jspexception, ioexception {
// Todo auto-generated method stub
// The system automatically calls and encapsulates the content in the TAG body into an object.
Jspfragmentjf = This. getjspbody (); // obtain the TAG body object.
JF. Invoke (this. getjspcontext (). getout (); // output to the client
// JF. Invoke (null); // output to the client
Super. dotag ();
}
}
ScriptlessNo script.
Control iteration w
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.