java Tomcat 上不存在包 javax.servlet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17008828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:41:54  来源:igfitidea点击:

package javax.servlet does not exist on Tomcat

javatomcatservletsnetbeansjapplet

提问by Aclber

I am writing JApplet in Netbeans. My applet is working, so I decide to add servlet because I want to have log in/out. When I added servlet to my project as follows:

我正在用 Netbeans 编写 JApplet。我的小程序正在运行,所以我决定添加 servlet,因为我想登录/注销。当我将 servlet 添加到我的项目时,如下所示:

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

I had the following errors:

我有以下错误:

error: package javax.servlet does not exist 
import javax.servlet.ServletException;
error: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;

Apache Tomcat is working.

Apache Tomcat 正在运行。

回答by Chris

Add servlet jarto the classpath in your IDE. Your webcontainer will provide it at runtime. You don't have to bundle it in your WAR

servlet jar添加到 IDE 中的类路径。您的 webcontainer 将在运行时提供它。您不必将其捆绑在 WAR 中