When producing a new Java Servlet in Eclipse IDE, you may encounter the adhering to errors:

HttpServlet can not be solved to a typeHttpServletRequest can not be addressed to a typeHttpServletResponse cannot be addressed to a typeServletException can not be solved to a typeThe income javax.servlet can not be resolvedWebServlet can not be addressed to a typeIt look at something choose this screenshot in Eclipse:

The factor is the Java Servlet API is missing in the project’s classpath. You can solve this trouble by specifying a server runtime for the project, e.g. Apache Tomcat runtime – because a Java internet server is a servlet container that implements the Servlet API.In Eclipse, right click on the project, click Properties. In the project properties dialog, click Java develop Path, and click the button Add Library… as shown below:
In the include Library dialog appears, choose Server Runtime:
Click Next. In the next screen select Apache Tomcat and click Finish:
If you nothing see any kind of Apache Tomcat servers here, most likely you haven’t set up Tomcat nor added to Eclipse. So monitor this accuse to add Tomcat in Eclipse.Click Finish to close the Server Library dialog, and you will check out the server library Apache Tomcat appears:
Then click Apply and Close, the errors will be gone.In instance you use Maven, the systems would it is in simpler. Just add a dependency for Java Servlet API in the pom.xml document like this:

javax.servletjavax.servlet-api3.0.1providedSave the file and wait for seconds for Maven to upgrade the project. You will watch the errors space gone way.

You are watching: Java cannot be resolved to a type

NOTE: To prevent this error in future, friend should choose the Target Runtime as Apache Tomcat when producing the job in Eclipse:

Other Java Servlet Tutorials:

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java throughout Java 1.4 and also has been falling in love with Java since then. Make friend with him on Facebook and also watch his Java videos you YouTube.
Add comment

Notify me of follow-up comments

I set build route for Java.servlet.Servlet in my eclipse IDE yet still it shows same error "The income javax.servlet cannot be resolved".all measures that you pointed out in your that done however still not working what I can do please assist me.
Solved ..Thanks.. It worked for me
Same trouble again. I am utilizing latest versions.

See more: Sound Not Working?: Roblox Audio Not Playing Audio Not Playing

Thank you.It functioned for me.
Thanks!! functioned just fine!!
Refresh comments list

See every Java Tutorials rwandachamber.org shares Java tutorials, code examples and sample tasks for programmers at all levels. Rwandachamber.org is created and also managed through Nam Ha Minh - a passionate programmer.

Home around Contact regards to Use Privacy plan Facebook TwitterYouTube