[英]My custom jsp tag library throws an error HTTP Status 500 - Unable to compile class for JSP
我的自定義jsp標記庫引發錯誤HTTP Status 500-無法為JSP編譯類,並且如果刷新同一頁面,它將出現新錯誤HTTP Status 500-java.lang.ClassNotFoundException:org.apache.jsp。 jspstn_jsp。 通過從jsp中刪除taglib指令和自定義tld的標記,我感到很累,無法正常工作。 我不知道我的代碼有什么問題。
jsp文件:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tlds/ct.tld" prefix="cp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! jspstn</h1>
<cp:tp></cp:tp>
</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>ct</short-name>
<uri>/WEB-INF/tlds/ct</uri>
<tag>
<name>tp</name>
<body-content>empty</body-content>
<tag-class>ctc</tag-class>
</tag>
</taglib>
自定義tld類(標記處理程序類):
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class ctc extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
JspWriter hp = getJspContext().getOut();
hp.print("works");
}
}
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<jsp-config>
<taglib>
<taglib-location>/WEB-INF/tlds/ct.tld</taglib-location>
<taglib-uri>/WEB-INF/tlds/ct.tld</taglib-uri>
</taglib>
</jsp-config>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
錯誤:
HTTP Status 500 - Unable to compile class for JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 17 in the jsp file: /jspstn.jsp
ctc cannot be resolved to a type
14: </head>
15: <body>
16: <h1>Hello World! jspstn</h1>
17: <cp:tp></cp:tp>
18: </body>
19: </html>
錯誤2:
HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.jspstn_jsp
type Exception report
message java.lang.ClassNotFoundException: org.apache.jsp.jspstn_jsp
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.jspstn_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:176)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:380)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.ClassNotFoundException: org.apache.jsp.jspstn_jsp
java.net.URLClassLoader.findClass(URLClassLoader.java:381)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:129)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:60)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:171)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:380)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Netbeans 8.2,Tomcat 8.5.8。 如果在回答我的問題時需要其他信息,請刪除評論。 抱歉打錯了
在您的標記庫描述符(tld)文件中,指定該類的標准程序包名稱 。
代替
<tag-class>ctc</tag-class>
做
<tag-class>your.package.ctc</tag-class>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.