我的github
posts - 3243,  comments - 42,  views - 158万

右键Application-->Properties-->Java Build Path-->Libraries-->Add External JARs-->servlet-api.jar

从而解决import javax.servlet.*;找不到类库的问题。

当然servlet-api.jar是在Tomcat自带的。安装目录下lib文件夹下可找到。

若没安装Eclipse,需要在CLASSPATH添加servlet-api.jar的目录,然后开始-->运行-->"cmd"进入DOS命令提示框,通过cd + 硬盘目录进入.java文件存放目录,通过javac + 文件名即可编译成功。

>>将编译好的Servlet服务器程序布设在Tomcat目录下

在..\Tomcat\webapps\ROOT\WEB-INF下新建classes和lib文件夹。将编译好的.class放在classes文件夹下,将servelt-api.rar放在lib文件夹下,将web.xml编辑为如下结构:

<?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 work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "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>

在浏览器中输入:http://localhost:8080/servlet/EchoForm即可。

posted on   XiaoNiuFeiTian  阅读(1189)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示