Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve symbol 'servlet'

I got this big newbie question. When i try the following; the 'servlet' turns red and indicates 'Cannot resolve symbol 'servlet'.

import javax.servlet.http.*;
import javax.servlet.ServletException;

I got apache tomcat running. I am a very big java newbie. Can anyone help me where to find a servlet library or something ? I googled but got no clear explanation of how to make this work.

This is the content of my web.xml file;

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>
        HelloWorld
    </display-name>
    <description>
        This is my first webapp
    </description>

    <servlet>
        <servlet-name>Hello world!</servlet-name>
        <description>This is a hello world servlet</description>
        <servlet-class>servlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWorldServlet</servlet-name>
        <url-pattern>HelloWorldServlet</url-pattern>
    </servlet-mapping>

</web-app>

EDIT: I use the IntelliJ IDEA IDE. And I am using Maven.

like image 857
Ben Avatar asked Feb 28 '12 09:02

Ben


2 Answers

The servlet jar needs to be in your build path.

If you are using maven you could do this :

<dependency>
 <groupId>org.apache.tomcat</groupId>
 <artifactId>tomcat-servlet-api</artifactId>
 <version>7.0.21</version>
 <scope>provided</scope>
</dependency>

Or use one of the providers listed here, Such as the below which is not dependent on a specific container :

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>3.0.1</version>
   <scope>provided</scope>
</dependency>
like image 190
NimChimpsky Avatar answered Nov 10 '22 15:11

NimChimpsky


Sounds like you're missing a classpath entry for servlet.jar. You haven't told us how you're building this, but basically you need to compile against servlet.jar. You shouldn't need to explicitly put it anywhere for execution time, as Tomcat should take care of that.

like image 45
Jon Skeet Avatar answered Nov 10 '22 14:11

Jon Skeet