0
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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user5501265
  • 39
  • 1
  • 8
  • try this: `javac -classpath javax.servlet.jsp.jstl-1.2.1.jar TagHandler.java` – Ajay Kulkarni Apr 06 '16 at 05:43
  • @AjayKulkarni thanks for replying i did exactly the same . – user5501265 Apr 06 '16 at 05:46
  • Did it work? Your command was `javac -cp "C:\Users\dell\Desktop\jst l2\WEB-INF\lib\javax.servlet.jsp.jstl-1.2.1.jar;" `, I don't see `.java` file in your command – Ajay Kulkarni Apr 06 '16 at 05:47
  • @AjayKulkarni Its not working – user5501265 Apr 06 '16 at 05:47
  • @AjayKulkarni java file is there its in the next line bro – user5501265 Apr 06 '16 at 05:48
  • @AjayKulkarni javac -cp "C:\Users\dell\Desktop\jst l2\WEB-INF\lib\javax.servlet.jsp.jstl-1.2.1.jar;" MyTagHandler.java – user5501265 Apr 06 '16 at 05:49
  • Why don't you add that library and your .java file in the same directory and try out without double quotations? – Ajay Kulkarni Apr 06 '16 at 05:50
  • @AjayKulkarni Its not working still i tried _C:\Users\dell\Desktop\jstl2\WEB-INF\classes>javac -cp javax.servlet.jsp.jstl-1.2 .1.jar MyTagHandler.java_ – user5501265 Apr 06 '16 at 05:52
  • What is the error? – Ajay Kulkarni Apr 06 '16 at 05:53
  • 8 errors bro MyTagHandler.java:5: error: package javax.servlet.jsp does not exist import javax.servlet.jsp.JspException; ^ MyTagHandler.java:6: error: package javax.servlet.jsp does not exist import javax.servlet.jsp.JspWriter; ^ MyTagHandler.java:5: error: package javax.servlet.jsp does not exist import javax.servlet.jsp.JspException; ^ MyTagHandler.java:6: error: package javax.servlet.jsp does not exist import javax.servlet.jsp.JspWriter; ^ @AjayKulkarni – user5501265 Apr 06 '16 at 05:55
  • Oh... add that `javax.servlet.jsp` in same folder and try again. You are using `import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport;`, but there is no supporting library for that – Ajay Kulkarni Apr 06 '16 at 05:57
  • @AjayKulkarni you mean i should import javax.servlet.jsp.*; is that? – user5501265 Apr 06 '16 at 06:02
  • @AjayKulkarni can you edit my code its still not working – user5501265 Apr 06 '16 at 06:09
  • Download jar file from this link: http://www.java2s.com/Code/Jar/j/Downloadjavaxservletjar.htm,, add it to the same directory and compile again – Ajay Kulkarni Apr 06 '16 at 06:27

1 Answers1

1

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?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555