Cannot resolve servlet character

I have this big question for newbies. When I try the following; the "servlet" turns red and indicates "Cannot resolve the servlet symbol.

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

I'm running cat apache. I am a very big newbie in java. Can someone help me find a servlet library or something else? I googled but did not get a clear explanation of how to make this work.

This is the contents 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 am using the IntelliJ IDE IDE. And I use Maven.

+8
java web-applications servlets
source share
5 answers

The servlet cell should be in your build path.

If you are using maven, you can 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 suppliers listed below, for example below, which is independent of a specific container:

 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> 
+12
source share

It looks like you are missing the classpath element for servlet.jar. You did not tell us how you are building this, but basically you need to compile the servlet.jar file. You do not need to explicitly point it anywhere at runtime, as Tomcat has to take care of this.

+3
source share

You are missing the servlet box in your classpath.add the same jar in your classpath.

If you are using Eclipse, right-click the project.

 -->Properties --->Java build path --->select Libraries 

add jar there.

+2
source share
 <servlet> <servlet-name>Hello world!</servlet-name> <description>This is a hello world servlet</description> <servlet-class>servlet</servlet-class> <--here is full name of your servlet class. </servlet> <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name><--here must be match <servlet-name> <url-pattern>HelloWorldServlet</url-pattern> </servlet-mapping> 
0
source share

The first time I used IntelliJ IDEA, I have the same problem, but I think the principle should be like Eclipse, just configure our required jar file in an external library.

Go to "File" ----> "Project Structure" ----> "Library", then press the button and add the necessary jar.

Cannot find the Servlet, it seems that you have lost the server-api.jar file, just put it in your library. And if you want to build a j2ee project, this simple file does not make sense.

So just put the whole local tomcat / lib jar file in your project, and the function will be the same as eclipse (configure build path → runtime server ...).

0
source share

All Articles