Jsp 无法加载标记处理程序类
我在标记pachage中有一个类,它用于tld文件Jsp 无法加载标记处理程序类,jsp,custom-tags,tag-handler,Jsp,Custom Tags,Tag Handler,我在标记pachage中有一个类,它用于tld文件 package tag; import java.io.IOException; import java.time.LocalDate; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; public class printDateTag extends
package tag;
import java.io.IOException;
import java.time.LocalDate;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class printDateTag extends TagSupport{
@Override
public int doStartTag() throws JspException {
try {
JspWriter writer = pageContext.getOut();
writer.print(LocalDate.now());
} catch (IOException ex) {System.out.println(ex);}
return SKIP_BODY;
}
}
我使用该类的tld文件如下
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" 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">
<tlib-version>1.0</tlib-version>
<short-name>tags</short-name>
<uri>/WEB-INF/tlds/tags</uri>
<tag>
<name>printDate</name>
<tag-class>tag.printDateTag</tag-class>
</tag>
1
标签
/WEB-INF/tlds/tags
打印日期
tag.printDateTag
我遇到错误的jsp是
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ta" uri="/WEB-INF/tlds/tags.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<ta:printDate/>
<a href="index">go</a>
</body>
</html>
JSP页面
在
中,我遇到了一个错误,无法按照您看到的代码为标记“ta:printDate加载标记处理程序类“tag.printDateTag”
看起来您的tld文件未正确配置
请参阅下面我尝试过的代码
printDateTag.java
package tag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class printDateTag extends TagSupport{
@Override
public int doStartTag() throws JspException {
try {
JspWriter writer = pageContext.getOut();
writer.print("<u>Hello From Tag</u>"); // <u>Hello From Tag</u>... it will display on JSP page
} catch (IOException ex) {System.out.println(ex);}
return SKIP_BODY;
}
}
包装标签;
导入java.io.IOException;
导入javax.servlet.jsp.JspException;
导入javax.servlet.jsp.JspWriter;
导入javax.servlet.jsp.tagext.TagSupport;
公共类printDateTag扩展了标记支持{
@凌驾
public int doStartTag()抛出JSPEException{
试一试{
JspWriter writer=pageContext.getOut();
writer.print(“来自标记的你好”);//来自标记的你好……它将显示在JSP页面上
}catch(IOException ex){System.out.println(ex);}
返回跳过单元体;
}
}
标签。tld
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>simple</short-name>
<!-- <uri>http://tomcat.apache.org/example-taglib</uri> -->
<uri>/WEB-INF/tlds/tags</uri>
<tag>
<name>printDate</name>
<tag-class>tag.printDateTag</tag-class>
</tag>
</taglib>
1
1.2
简单的
/WEB-INF/tlds/tags
打印日期
tag.printDateTag
test.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ta" uri="/WEB-INF/tlds/tags.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<ta:printDate/>
<a href="index">go</a>
</body>
</html>
JSP页面
输出:
TLD必须包含在
WEB-INF/TLD
目录中。你能检查一下TLD是否在正确的位置吗?好吧,现在我真的感到抱歉和愚蠢,我实际上从未尝试运行过这个,我假设它会给我500分,因为它是一个红色错误,它工作正常,而且所有的,它只是在jsp上不断给我那个错误页