简体   繁体   English

为什么javax.servlet无法导入?

[英]why is javax.servlet not available for import?

I have java sdk 1.7. 我有Java SDK 1.7。 I've always used django/python for web development, this will be the first time I use java. 我一直使用django / python进行网络开发,这将是我第一次使用java。

When I tried: 当我尝试:

import javax.servlet.http.*;

servlet is not found? 找不到servlet? How do I properly install this servlet jar? 如何正确安装此servlet jar?

EDIT: 编辑:

I am developing some small stuff for google app engine using java. 我正在使用Java为Google App Engine开发一些小东西。

它不是标准JDK附带的,您需要在类路径中添加servlet-api.jar

"javax.servlet.*" and friends come with whatever servlet container you're using. “ javax.servlet。*”和朋友随您使用的任何servlet容器一起提供。 Tomcat uses j2ee.jar or servlet.jar (IIRC), WebSphere uses a different .jar, etc. Tomcat使用j2ee.jar或servlet.jar(IIRC),WebSphere使用其他.jar等。

You're using Google App Engine. 您正在使用Google App Engine。

That means you need to use the Google .jar files. 这意味着您需要使用Google .jar文件。

Here's the documentation: 这里是文档:

https://developers.google.com/appengine/docs/java/runtime https://developers.google.com/appengine/docs/java/runtime

App Engine knows to use the Java runtime environment for your application when you use the AppCfg tool from the Java SDK to upload the app. 当您使用Java SDK中的AppCfg工具上传应用程序时,App Engine会为您的应用程序使用Java运行时环境。

There is only one version of the App Engine Java API. App Engine Java API只有一个版本。 This API is represented by the appengine-api-*.jar included with the SDK (where * represents the version of the API and the SDK). 该API由SDK随附的appengine-api-*。jar表示(其中*表示API和SDK的版本)。 You select the version of the API your application uses by including this JAR in the application's WEB-INF/lib/ directory. 通过将此JAR包含在应用程序的WEB-INF / lib /目录中,可以选择应用程序使用的API版本。 If a new version of the Java runtime environment is released that introduces changes that are not compatible with existing apps, that environment will have a new version number. 如果发布的Java运行时环境新版本引入了与现有应用程序不兼容的更改,则该环境将具有新的版本号。 Your application will continue to use the previous version until you replace the JAR with the new version (from a newer SDK) and re-upload the app. 您的应用程序将继续使用以前的版本,直到您用新版本(通过更新的SDK)替换JAR并重新上传该应用程序为止。

it doesnt come with disttribution of core J2Se distibution ..because this API depends on which server(tomcat, jetty) you are using . 它没有随核心J2Se分发一起提供..,因为此API取决于您所使用的服务器(tomcat,jetty)。 so it comes with the server . 因此它随服务器一起提供。 If you are using tomcat its there in tomcat lib directry witth name of servler-api.jar . 如果您使用的是tomcat,则它位于tomler lib目录中,名称为servler-api.jar。 add it to your classpath 将其添加到您的类路径中

If your IDE is Intellij you'll have to get the Ultimate version. 如果您的IDE是Intellij,则必须获得Ultimate版本。

Below are the features of Intellij IDEA ultimate edition . 以下是Intellij IDEA旗舰版的功能

  • Full-featured IDE for JVM-based and polyglot development 全功能IDE,用于基于JVM和多语言的开发
  • Java EE, Spring/Hibernate and other technologies support Java EE,Spring / Hibernate和其他技术支持
  • Deployment and debugging with most application servers 使用大多数应用程序服务器进行部署和调试
  • Duplicate code search, dependency structure matrix, etc. 重复代码搜索,依赖结构矩阵等。

Then you can easily start a Intellij J2EE project which will include all the necessary jars in the classpath. 然后,您可以轻松地启动Intellij J2EE项目,该项目将在类路径中包含所有必需的jar。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM