This is a helloworld program.
Problems solved: 1. The project cannot be processed using EL expressions; 2. How should TLD be defined; 3. Custom a JSP tag
1. The El expression cannot be used.
(I am using the tomcat.6.0.36 version I just downloaded this evening. However, this problem does not matter to the tomcat version)
1) problems that always occur before. My original solution is to change the version number in the web. xml file from 2.5 to 2.4.
For example, <web-app version ="2.4"Xmlns =" http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app _2_4. XSD ">
But it does not feel good.
2) The solution is to use the jar package in Java ee 5 librariesCopy to the lib directory of the projectThis problem is solved.
(My: http://download.csdn.net/detail/cl61917380/5227429)
2. How should TLD be defined?
1) For example, copy the tag. TLD file to the WEB-INF directory.
2) Some people ask how to find the official TLD file Definition Format. As longAdd XSD in the Document Header, Tell ide how to define my XML, so that the IDE will prompt us when writing the XML file.
<? XML version = "1.0" encoding = "UTF-8"?> <Taglib xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version = "2.1"> <tlibversion> 1.0 </tlibversion> <jspversion> 1.1 </jspversion> <tag> <Name> tag </Name> <tagclass> COM. jungle. tag. PAGETAG </tagclass> <bodycontent> Empty </bodycontent> <! -- Define Attributes --> <attribute> <Name> currentpage </Name> <! -- Attribute name --> <type> int </type> <! -- Property type --> <required> true </required> <! -- Required? --> <rtexprvalue> true </rtexprvalue> <! -- Supports El expressions --> </attribute> <Name> pagecount </Name> <! -- Attribute name --> <type> int </type> <! -- Attribute type --> </attribute> </Tag> </taglib>
3. Create a tag class
public class PageTag extends TagSupport {private int currentPage = 1;private int pageCount = 10;@Overridepublic int doStartTag() throws JspException {ServletResponse resp = this.pageContext.getResponse();try {PrintWriter writer = resp.getWriter();writer.print("doStartTag()..." + "currentPage = " + currentPage + " pageCount = " + pageCount);writer.flush();writer.close();} catch (IOException e) {e.printStackTrace();}return super.doStartTag();}public int getCurrentPage() {return currentPage;}public void setCurrentPage(int currentPage) {this.currentPage = currentPage;}public int getPageCount() {return pageCount;}public void setPageCount(int pageCount) {this.pageCount = pageCount;}}
JSP page:
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" GBK "%> <% @ taglib uri ="/WEB-INF/Tag. TLD "prefix =" PT "%> <! -- Introduce custom tags --> <% @ taglib prefix = "C" uri = "http://java.sun.com/jsp/jstl/core" %> <! -- The URI of 1.2 is used here, And the URI of 1.1 is the http://java.sun.com/jstl/core. I use both URI pages as normal --> <% request. setattribute ("currentpage", 3); // the current page request. setattribute ("content", "query keyword"); // query keyword %> <PT: Tag currentpage = "$ {currentpage}" pagecount = "123"/> <br>