Gremo
28-09-2005, 21:36
EDIT: spiego un pò meglio...
Uso NetBeans IDE 4.1.
questa è struttura delle directory e dei file:
http://img317.imageshack.us/img317/3699/taglib8iz.png
questo è il file test.jsp:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="WEB-INF/tlds/mytags.tld" prefix="mytags"%>
<html>
<head>
<title></title>
</head>
<body>
<p><mytags:insert/></p>
</body>
</html>
nella jsp dico di usare il descrittore WEB-INF/tlds/mytags.tld:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>mytags</short-name>
<uri>/WEB-INF/tlds/mytags</uri>
<tag>
<name>insert</name>
<tag-class>SimpleTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
il descrittore dice alla jsp che il tag "insert" fa riferimento alla classe SimpleTag (contentuta coem si vede nella cartella WEB-INF/classes"
questo è il sorvete di SimpleTag
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
public class SimpleTag extends SimpleTagSupport {
public void doTag() throws JspException {
JspWriter out=getJspContext().getOut();
try {
out.println("funziono!");
} catch (java.io.IOException ex) {
throw new JspException(ex.getMessage());
}
}
}
ecco l'errore che mi dà
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 9 in the jsp file: /test.jsp
Generated servlet error:
C:\Documents and Settings\Gremo\.netbeans\4.1\jakarta-tomcat-5.5.7_base\work\Catalina\localhost\TestSimpleTag\org\apache\jsp\test_jsp.java:78: cannot find symbol
symbol : class SimpleTag
location: class org.apache.jsp.test_jsp
SimpleTag _jspx_th_mytags_insert_0 = new SimpleTag();
^
Uso NetBeans IDE 4.1.
questa è struttura delle directory e dei file:
http://img317.imageshack.us/img317/3699/taglib8iz.png
questo è il file test.jsp:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="WEB-INF/tlds/mytags.tld" prefix="mytags"%>
<html>
<head>
<title></title>
</head>
<body>
<p><mytags:insert/></p>
</body>
</html>
nella jsp dico di usare il descrittore WEB-INF/tlds/mytags.tld:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>mytags</short-name>
<uri>/WEB-INF/tlds/mytags</uri>
<tag>
<name>insert</name>
<tag-class>SimpleTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
il descrittore dice alla jsp che il tag "insert" fa riferimento alla classe SimpleTag (contentuta coem si vede nella cartella WEB-INF/classes"
questo è il sorvete di SimpleTag
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
public class SimpleTag extends SimpleTagSupport {
public void doTag() throws JspException {
JspWriter out=getJspContext().getOut();
try {
out.println("funziono!");
} catch (java.io.IOException ex) {
throw new JspException(ex.getMessage());
}
}
}
ecco l'errore che mi dà
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 9 in the jsp file: /test.jsp
Generated servlet error:
C:\Documents and Settings\Gremo\.netbeans\4.1\jakarta-tomcat-5.5.7_base\work\Catalina\localhost\TestSimpleTag\org\apache\jsp\test_jsp.java:78: cannot find symbol
symbol : class SimpleTag
location: class org.apache.jsp.test_jsp
SimpleTag _jspx_th_mytags_insert_0 = new SimpleTag();
^