Right-click Application-->properties-->java Build path-->libraries-->add External Jars-->servlet-api.jar
This solves the import javax.servlet.*, and the class library problem is not found.
Of course Servlet-api.jar is in Tomcat's own belt. The installation directory under the Lib folder can be found.
If you do not have eclipse installed, you need to add the Servlet-api.jar directory in Classpath and then start-and-run "cmd" into the DOS command prompt via CD + hard drive directory to enter the. java file directory, via Javac + The file name can be compiled successfully.
>> laying the compiled servlet server program in the Tomcat directory
In.. Create a new classes and Lib folder under \tomcat\webapps\root\web-inf. Place the compiled. Class in the Classes folder, place the Servelt-api.rar under the Lib folder, and edit the Web. Xml as follows:
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<!--
Licensed to the Apache software Foundation (ASF) under one or more
Contributor license agreements. See the NOTICE file distributed with
This is for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); Except in compliance with
The License. Obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to writing, software
Distributed under the License is distributed on a "as is" BASIS,
Without warranties or CONDITIONS of any KIND, either express or implied.
See the License for the specific language governing permissions and
Limitations under the License.
-
<web-app xmlns= "Http://java.sun.com/xml/ns/javaee"
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>welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>EchoForm</servlet-name>
<servlet-class>EchoForm</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EchoForm</servlet-name>
<url-pattern>/servlet/EchoForm</url-pattern>
</servlet-mapping>
</web-app>
In the browser, type: Http://localhost:8080/servlet/EchoForm.
Eclipse adds a reference to the Servlet-api.jar library