HitesH JaiN
HitesH JaiN

Reputation: 75

My custom jsp tag library throws an error HTTP Status 500 - Unable to compile class for JSP

My custom jsp tag library throws an error HTTP Status 500 - Unable to compile class for JSP and if i refresh the same page than it will land up with an new error HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.jspstn_jsp . I had tired by removing taglib directive and tag of my custom tld from jsp than it work's fine . I Don't know what's wrong i had made in my code .

jsp file :

<%@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>

custom tld file :

 <?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>

custom tld class (tag handler class) :

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 file :

 <?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>

Error :

   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>

Error 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 . If needed additional info in answering my question than please drop comment . Sorry in case of typos

Upvotes: 1

Views: 751

Answers (1)

Sundararaj Govindasamy
Sundararaj Govindasamy

Reputation: 8495

In your Tag Library descriptor (tld) file, Specify the fully qualified package name of the class.

Instead of

 <tag-class>ctc</tag-class>

do

<tag-class>your.package.ctc</tag-class>

Upvotes: 0

Related Questions