我似乎无法在我的JSPX 2.1项目中使用Tomcat 8获取JSP自定义标签用于爱和金钱,使用Eclipse Java EE IDE for Web Developers 4.4.1,在Firefox 35.0.1 Windows 8.1中进行测试。
症状:没有错误消息,它们只是被传递而且标签没有被处理,因为我在其中用于调试的打印语句根本没有被执行。内置的JSTL标签可以毫不费力地工作。
将我的头撞在墙上一段时间之后,我继续前进并尝试了另一个自定义标签。这也没有用,同样的症状。
我尝试过的事情: 我将我的代码与一本预先构建的示例Web项目进行了比较 - 本项目中的自定义标签被调用并正常执行,因此我怀疑这与项目配置有关 - 尽管我不知道,通过Eclipse中的属性页面拖网并没有显示任何明显的差异。 我还比较了上述示例中的web.xml配置和.tld配置,调整它们的版本号和.xsd引用是相同的,如果这是问题。 我已经看过类似的问题,他们特别关注在Maven中构建Tomcat 7的依赖关系,我已经专门检查了这些项目的依赖关系,并且相信它们是相同的。
.tld文件(在WEB-INF目录中)
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_1.xsd ">
<description>Auctioneers custom tags</description>
<tlib-version>1.0</tlib-version>
<short-name>dauct</short-name>
<tag>
<description>Create a user</description>
<display-name>createUser</display-name>
<name>createUser</name>
<tag-class>derbyauct.users.UserInsertTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>user</name>
<rtexprvalue>true</rtexprvalue>
<type>derbyauct.users.UserCreation</type>
</attribute>
</tag>
<tag>
<description>Returns auctions at status ready</description>
<display-name>returnReadyAuctions</display-name>
<name>returnReadyAuctions</name>
<tag-class>derbyauct.auctions.NextAuctionTag</tag-class>
<body-content>empty</body-content>
</tag>
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>auctioneers</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>
</description>
<display-name>AuctServlet</display-name>
<servlet-name>AuctServlet</servlet-name>
<servlet-class>auct.AuctServlet</servlet-class>
<init-param>
<param-name>base</param-name>
<param-value>/dauct</param-value>
</init-param>
<init-param>
<param-name>imageURL</param-name>
<param-value>/images/</param-value>
</init-param>
<init-param>
<param-name>jdbcDriver</param-name>
<param-value>org.mariadb.jdbc.Driver</param-value>
</init-param>
<init-param>
<param-name>dbURL</param-name>
<param-value>jdbc:mysql://localhost:3306/derbyauct</param-value>
</init-param>
<init-param>
<param-name>dbUserName</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>dbPassword</param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>AuctServlet</servlet-name>
<url-pattern>/dauct/</url-pattern>
</servlet-mapping>
</web-app>
标记处理程序
package auct.users;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.ServletContext;
import auct.utils.DALManager;
import auct.users.UserCreation;
public class UserInsertTag extends TagSupport {
static final long serialVersionUID = 1L;
private UserCreation user;
public UserCreation getUser() {
return user;
}
public void setUser(UserCreation user) {
this.user = user;
System.out.println("user object :" + user);
}
public int doEndTag() throws JspException {
ServletContext context = pageContext.getServletContext();
DALManager dm = (DALManager)context.getAttribute("dalManager");
try {
dm.insertUser(user);
}
catch (Exception e) {}
return EVAL_PAGE;
}
}
JSPX文件调用标记
<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:dauct="urn:jspltd:/WEB-INF/tlds/dauct.tld"
xmlns:c="http://java.sun.com/jsp/jstl/core"
version="2.3"
>
<jsp:directive.page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<c:url var="cssUrl" value="/css/dauct.jspx"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>User</title>
<link rel="stylesheet" href="${cssUrl}" type="text/css"/>
</head>
<body>
<jsp:include page="TopMenu.jspx" flush="true"/>
<jsp:include page="LeftMenu.jspx" flush="true"/>
<div class="content">
<h2>Registration Complete</h2>
<jsp:useBean id="user" class="auct.users.UserCreation" scope="request"/>
<jsp:setProperty property="*" name="user"/>
<dauct:createUser user="${user}"/>
<p class="info">
Thank you for registering.<br/>
Welcome to Auctioneers <c:out value="${user.firstName}"/>
</p>
</div>
</body>
</html>
</jsp:root>
lib文件夹
annotations-api.jar
catalina-ant.jar
catalina-ha.jar
catalina-storeconfig.jar
catalina-tribes.jar
catalina.jar
ecj-4.4.jar
el-api.jar
jasper-el.jar
jasper.jar
javax.servlet.jsp.jstl-1.2.1.jar
javax.servlet.jsp.jstl-api-1.2.1.jar
jsp-api.jar
list.txt
mariadb-java-client-1.1.8.jar
mysql-connector-java-5.1.34-bin.jar
servlet-api.jar
tomcat-api.jar
tomcat-coyote.jar
tomcat-dbcp.jar
tomcat-i18n-es.jar
tomcat-i18n-fr.jar
tomcat-i18n-ja.jar
tomcat-jdbc.jar
tomcat-jni.jar
tomcat-spdy.jar
tomcat-util-scan.jar
tomcat-util.jar
tomcat-websocket.jar
websocket-api.jar
答案 0 :(得分:0)
尝试使用指令taglib <%@taglib prefix="c" uri=""%>