In order to write servlets code I need servlet-api.jar. Where do i get servlet-api.jar from ?
For Eclipse user, when you run a servlet (right click on the servlet . java file and select Run as > Run on Server ), Eclipse automatically compiles the file before running it. To manually compile a Java servlet, you may need to set a classpath to include servlet-api. jar (presumably in apache-tomcat/lib/ folder).
You need Servlet-api. jar to compile servlets in eclipse but while deploying servlet container ( like tomcat ) will have it built in.
For adding a jar file, right click on your project -> Build Path -> Configure Build Path -> click on Libraries tab in Java Build Path -> click on Add External JARs button -> select the servlet-api. jar file under tomcat/lib -> ok. Now servlet has been created, Let's write the first servlet code.
What is it? The servlet-api jar is a library which contains the interfaces and classes of the Servlet API specification. The servlet-api jar contains only the interface (the API) of the Servlet Specification, so you can use it to develop your web application.
Make sure that you're using the same Servlet API specification that your Web container supports. Refer to this chart if you're using Tomcat: http://tomcat.apache.org/whichversion.html
The Web container that you use will definitely have the API jars you require.
Tomcat 6 for example has it in apache-tomcat-6.0.26/lib/servlet-api.jar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With