Eclipse adds a reference to the Servlet-api.jar library

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.