编译简单自定义标签时出错 class
Get an error when compiling Simple custom tag class
我创建了简单的自定义标签库。但是当我 运行 jsp 我在代码下面遇到了错误。谁能给我解释一下这个错误。
Compiling 1 source file to C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\classes
C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\src\org\apache\jsp\index_jsp.java:85: error: cannot find symbol
Test _jspx_th_t_test_0 = (_jspx_resourceInjector != null) ? _jspx_resourceInjector.createTagHandlerInstance(Test.class) : new Test();
^
symbol: class Test
location: class index_jsp
C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\src\org\apache\jsp\index_jsp.java:85: error: cannot find symbol
Test _jspx_th_t_test_0 = (_jspx_resourceInjector != null) ? _jspx_resourceInjector.createTagHandlerInstance(Test.class) : new Test();
^
symbol: class Test
location: class index_jsp
C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\src\org\apache\jsp\index_jsp.java:85: error: cannot find symbol
Test _jspx_th_t_test_0 = (_jspx_resourceInjector != null) ? _jspx_resourceInjector.createTagHandlerInstance(Test.class) : new Test();
^
symbol: class Test
location: class index_jsp
3 errors
C:\Users\Senani\Documents\NetBeansProjects\JSTL\nbproject\build-impl.xml:953: The following error occurred while executing this line:
C:\Users\Senani\Documents\NetBeansProjects\JSTL\nbproject\build-impl.xml:296: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)
XML代码
<?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>lb1</short-name>
<uri>/WEB-INF/tlds/lb1</uri>
<tag>
<name>test</name>
<body-content>empty</body-content>
<tag-class>Test</tag-class>
</tag>
</taglib>
JSP代码
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" uri="/WEB-INF/tlds/lb1.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<t:test/>
</body>
</html>
我的Javaclass
public class Test extends SimpleTagSupport{
@Override
public void doTag() throws JspException, IOException {
System.out.println("tag work");
}
}
更新了问题
我将 java class 移动到文件夹。但是编译的时候还是报错。
org.apache.jasper.JasperException:
file:C:/Users/Senani/Documents/NetBeansProjects/JSTL/build/web/index.jsp(17,8)
PWC6032: Unable to load tag handler class "Test" for tag "t:test"
org.apache.jasper.JasperException: PWC6032: Unable to load tag
handler class "Test" for tag "t:test"
C:/Users/Senani/Documents/NetBeansProjects/JSTL/build/web/index.jsp(17,8)
C:\Users\Senani\Documents\NetBeansProjects\JSTL\nbproject\build-impl.xml:936:
Java returned: 1 BUILD FAILED (total time: 1 second)
你得到那个错误是因为你把你的 class 放在默认包里。
永远不要那样做。使用正确的包,并确保在 XML 文件中指定 class 的完全限定名称。
我创建了简单的自定义标签库。但是当我 运行 jsp 我在代码下面遇到了错误。谁能给我解释一下这个错误。
Compiling 1 source file to C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\classes
C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\src\org\apache\jsp\index_jsp.java:85: error: cannot find symbol
Test _jspx_th_t_test_0 = (_jspx_resourceInjector != null) ? _jspx_resourceInjector.createTagHandlerInstance(Test.class) : new Test();
^
symbol: class Test
location: class index_jsp
C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\src\org\apache\jsp\index_jsp.java:85: error: cannot find symbol
Test _jspx_th_t_test_0 = (_jspx_resourceInjector != null) ? _jspx_resourceInjector.createTagHandlerInstance(Test.class) : new Test();
^
symbol: class Test
location: class index_jsp
C:\Users\Senani\Documents\NetBeansProjects\JSTL\build\generated\src\org\apache\jsp\index_jsp.java:85: error: cannot find symbol
Test _jspx_th_t_test_0 = (_jspx_resourceInjector != null) ? _jspx_resourceInjector.createTagHandlerInstance(Test.class) : new Test();
^
symbol: class Test
location: class index_jsp
3 errors
C:\Users\Senani\Documents\NetBeansProjects\JSTL\nbproject\build-impl.xml:953: The following error occurred while executing this line:
C:\Users\Senani\Documents\NetBeansProjects\JSTL\nbproject\build-impl.xml:296: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)
XML代码
<?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>lb1</short-name>
<uri>/WEB-INF/tlds/lb1</uri>
<tag>
<name>test</name>
<body-content>empty</body-content>
<tag-class>Test</tag-class>
</tag>
</taglib>
JSP代码
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" uri="/WEB-INF/tlds/lb1.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<t:test/>
</body>
</html>
我的Javaclass
public class Test extends SimpleTagSupport{
@Override
public void doTag() throws JspException, IOException {
System.out.println("tag work");
}
}
更新了问题
我将 java class 移动到文件夹。但是编译的时候还是报错。
org.apache.jasper.JasperException:
file:C:/Users/Senani/Documents/NetBeansProjects/JSTL/build/web/index.jsp(17,8)
PWC6032: Unable to load tag handler class "Test" for tag "t:test"
org.apache.jasper.JasperException: PWC6032: Unable to load tag
handler class "Test" for tag "t:test"
C:/Users/Senani/Documents/NetBeansProjects/JSTL/build/web/index.jsp(17,8)
C:\Users\Senani\Documents\NetBeansProjects\JSTL\nbproject\build-impl.xml:936:
Java returned: 1 BUILD FAILED (total time: 1 second)
你得到那个错误是因为你把你的 class 放在默认包里。
永远不要那样做。使用正确的包,并确保在 XML 文件中指定 class 的完全限定名称。