I got an error while creating a servlet in eclipse like
Multiple markers at this line
- ServletException cannot be resolved to a type
- HttpServletResponse cannot be resolved to a type
- HttpServletRequest cannot be resolved to a type
This question is related to
eclipse
servlets
jakarta-ee
compiler-errors
Two possible issues could be
To include Servlet jar in your class path in eclipse, Download the latest Servlet Jar and configure using buildpath option. look at this Link for more info.
If you have included the jar make sure that your import is declared.
import javax.servlet.http.HttpServletResponse
You can do the folllwoing: import the jar file inside you class:
import javax.servlet.http.HttpServletResponse
add the Apache Tomcat library as follow:
Project > Properties > Java Build Path > Libraries > Add library from library tab > Choose server runtime > Next > choose Apache Tomcat v 6.0 > Finish > Ok
Also First of all, make sure that Servlet jar is included in your class path in eclipse as PermGenError said.
I think this will solve your error
Project > Properties > Java Build Path > Libraries > Add library from library tab > Choose server runtime > Next > choose Apache Tomcat v 7.0> Finish > Ok
Select Tomcat server in Targeted Runtime
Project->Properties->Targeted Runtimes (Select your Tomcat Server)
if you are using maven:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
As a reason of this problem, some code is broken or undefined.You may see an error in a java class such as "The type javax.servlet.http.HttpSession cannot be resolved. It is indirectly referenced from required .class files". you shuold download " javax.servlet.jar" as mentioned before. Then configure your project build path, add the javax.servlet.jar as an external jar.I hope it fixes the problem.At least it worked for me.
Are the classes imported? Try pressing CTRL
+ SHIFT
+ O
to resolve the imports. If this does not work you need to include the application servers runtime libraries.
Source: Stackoverflow.com