⛔️ The import javax.servlet can't be resolved

import java.servlet cannot be resolved error.png
If you receive the above error message in your java files (servlet classes) while working with eclipse IDE then you are most probably missing the API servlet-api.jar file that is needed by your project.
How to resolve javax.servlet error!- Make sure that you have installed Apache Tomcat Server and have configured it to run your Application.
- Right Click on your Project folder,
- Now click on Properties at the bottom
- Select Java Build Path on the right.
- Go to Library tab.
- Click on Add External Library.
- Now go to the location where Apache Tomcat has been installed (e.g. : c:\apache-tomcat-7.0.101).
- Now go to lib directory and Select servlet-api jar file.
- Apply Changes (Save).
- Just Clean + Build your project.
- The errors must now get resolved.

Right-Click-on-Project-Folder-and-Select-Properties.png

Add-servlet-api-jar.png
Note: Alternatively, you just copy the servlet-api jar file to the lib folder of your project
package com.code2care.org;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
public class ServletError extends HttpServlet
{
/**
* HTTP doGet request.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("Resolving Servlet Jar exception ");
out.println("");
out.println("Get : This works!.
");
out.println("");
out.close();
}
/**
* HTTP doPost request.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("Resolving Servlet Jar Exception ");
out.println("");
out.println("Post : This works!.
");
out.println("");
out.close();
}
}
More Posts related to Java,
- Convert Java Map Collection Object to JSON String using Jackson
- Java Stream flatmap() Examples
- [Fix] Instant java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years
- How to run Java Unit Test cases with Apache Maven?
- How to check if Java main thread is alive
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Parsing CSV file using Java code example (Comma Separated File)
- Unhandled exception type InterruptedException : Java Threads
- Native getClass() method from java.lang.Object Class Explained with examples.
- Java Jackson ObjectMapper Class with Examples
- Java 8 Streams map() with examples
- Java 8 - Convert List to Map Examples
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- Java Stream with Multiple Filters Example
- How to Clear StringJoiner in Java 8
- Spring 5 IoC Example with application Context XML (ClassPathXmlApplicationContext) and Gradle.
- How to get end of line (EOL) or new line character \r \n in Java
- Spring Boot CRUD Examples using JDBCTemplate
- Delete a File in Java with Examples
- Implementing Insertion Sort Algorithm in Java Program
- Java JDBC Batch Update Example with PreparedStatement
- Java JDBC Select Multiple Records from table as List using PreparedStatement
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to fix Java HTTP java.net.UnknownHostException
- Java 8 Display time in 12 hour AM PM format
More Posts:
- Error: Failed to validate the signature of the actionable message card - Power Automate Flow - PowerAutomate
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example - Java
- How to Preview HTML, CSS, JavaScript in Notepad++ - NotepadPlusPlus
- Is Facebook is down? Is it just for me? - Facebook
- Adding Jackson dependency to Java Gradle Project - Gradle
- Set Falling Show on Website for Christmas using Pure CSS Code - CSS
- How to create a Array (not using list) in Python - Python
- Fix: Jupyter Notebook says Not Trusted - Python