Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServletException, HttpServletResponse and HttpServletRequest cannot be resolved to a type [duplicate]

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
like image 773
BAlu BAlaji Avatar asked Dec 19 '12 11:12

BAlu BAlaji


People also ask

What is the use of @WebServlet annotation?

Use the @WebServlet annotation to define a servlet component in a web application. This annotation is specified on a class and contains metadata about the servlet being declared. The annotated servlet must specify at least one URL pattern. This is done by using the urlPatterns or value attribute on the annotation.

What is javax servlet http package?

The javax. servlet. http package contains a number of classes and interfaces that describe and define the contracts between a servlet class running under the HTTP protocol and the runtime environment provided for an instance of such a class by a conforming servlet container.


2 Answers

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

like image 130
Areeg Samir Avatar answered Sep 28 '22 08:09

Areeg Samir


Two possible issues could be

  • you either forgot to include Servlet jar in your classpath
  • you forgot to import it in your Servlet class

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
like image 41
PermGenError Avatar answered Sep 28 '22 07:09

PermGenError