簡體   English   中英

編譯簡單的自定義標簽類時出現錯誤

[英]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>

我的Java課

 public class Test extends SimpleTagSupport{

        @Override
        public void doTag() throws JspException, IOException {
            System.out.println("tag work");
        }

    }

更新了問題


我將Java類移動到了文件夾。 但編譯時仍然出現錯誤。

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)

之所以會收到該錯誤,是因為您將類放在默認包中。

永遠不要那樣做。 使用適當的包,並確保在XML文件中指定類的完全限定名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM