Compile custom JSP tag handler

659 Views Asked by At
package com.mytag.tags;

import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class MyTagHandler extends SimpleTagSupport{

public int doStartTag() throws JspException {
    JspWriter out=pageContext.getOut();
    try{
        out.print(new java.util.Date());
    }catch(Exception e){System.out.println(e);}
    return SKIP_BODY;
    }

}

Need to compile this custom JSP tag handler without use of any IDE. Can anyone please mention how to compile it i tried javac -cp "C:\Users\dell\Desktop\jst l2\WEB-INF\lib\javax.servlet.jsp.jstl-1.2.1.jar;" MyTagHandler.java It's not Working

1

There are 1 best solutions below

0
On

This code is not JSTL at all. This code is a custom JSP taghandler. JSTL are those tags which you import in JSP via http://java.sun.com/jsp/jstl/* namespace URI, such as <c:xxx>, <fmt:xxx>, etc. JSTL does not represent "custom JSP taghandlers". To learn more about what exactly JSTL is, head to our JSTL wiki page.

As to your concrete problem, you just need to have JSP API in the runtime classpath. This should already be hinted by the package names of the imports: javax.servlet.jsp.*. You don't have imported javax.servlet.jsp.jstl.* anywhere, so the JSTL API JAR file is unnecessary.

You normally find the JSP API JAR file in the library/module folder of the target server. The fact that you manually placed JSTL in /WEB-INF/lib folder suggests that you're not targeting a real Java EE server such as WildFly, TomEE, etc, but a barebones servletcontainer such as Tomcat. I'll therefore assume Tomcat as an example. You can find the JSP API in the /lib folder of Tomcat installation.

Assuming Tomcat is installed (unzipped) in C:\Java\apache-tomcat-8.0.33, here's the correct command to compile the custom JSP taghandler:

javac -cp "C:\Java\apache-tomcat-8.0.33\lib\jsp-api.jar" com/mytag/tags/MyTagHandler.java

Note that this will pop out "cannot find symbol" compilation error, but that part is completely unrelated to the question currently asked. In order to solve the new compilation error, head to What does a "Cannot find symbol" compilation error mean?