javax.servlet.http.HTTPServlet导入无法在包的其余部分导入时解析

时间:2021-02-02 18:08:22

I am working on a tutorial to learn how to build a basic web app on eclipse, run locally on tomcat. However I can't seem to access the HTTPServlet class, while it appears that I can still import other javax.servlet.http files.

我正在编写一个教程,学习如何在eclipse上构建一个基本的web应用程序,在tomcat上本地运行。但是我似乎无法访问HTTPServlet类,而看起来我仍然可以导入其他javax.servlet.http文件。

package org.eclipse.wtp.tutorial;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HTTPServlet; //This import has an error, "Cannot be resolved"
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SnoopServlet extends HTTPServlet {}

I have gone through these stack overflow answers with no changes to my situation:
Importing servlet API
Adding Runtime

我已经完成了这些堆栈溢出答案而没有改变我的情况:导入servlet API添加运行时

And I wanted to try the second answer of adding a dependency to the project, but there is no pom, and this way of adding a dependency isn't working for me (I don't have the options necessary to do #3)

我想尝试在项目中添加依赖项的第二个答案,但是没有pom,这种添加依赖项的方式对我来说不起作用(我没有做必要的选项#3)

What is going wrong here?

这里出了什么问题?

2 个解决方案

#1


1  

In Java, class names are case sensitives. The correct name is HttpServlet (lowercase).

在Java中,类名称区分大小写。正确的名称是HttpServlet(小写)。

#2


0  

import javax.servlet.http.HttpServlet; //this is correct
import javax.servlet.http.HTTPServlet; //incorrect

#1


1  

In Java, class names are case sensitives. The correct name is HttpServlet (lowercase).

在Java中,类名称区分大小写。正确的名称是HttpServlet(小写)。

#2


0  

import javax.servlet.http.HttpServlet; //this is correct
import javax.servlet.http.HTTPServlet; //incorrect