Eclipse添加servlet-api.jar库的引用
2015-08-10 17:53
671 查看
右键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即可。
从而解决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即可。
相关文章推荐
- I学霸官方免费教程九:Java基础之成员变量(全局变量)和局部变量
- 智渔课堂官方免费教程八:Java基础之方法(函数)
- I学霸官方免费教程八:Java基础之方法(函数)
- java实现无序整数数组组合得出最大数,如array={1,2,3},array2={123,132,213,231,312,321}。最大数是321
- [Java] 语法基础
- (๑• . •๑)菜鸟入门我的小九九之JAVA版
- Java中Hashmap的遍历方法
- java Struts2 Zxing生成一维码
- 解决Myeclipse在调试(debug)时无法显示变量值问题
- Eclipse 中 新建maven项目 无法添加src/main/java 问题
- [JavaWeb基础] 010.Struts2 下载文件
- Eclipse 10个常用快捷键
- Java Security安全系列文档翻译笔记————数字签名、keystore、证书
- javaproject更新后仍然报找不到类或属性
- spring mvc void 不加@ResponseBody 404
- spring 配置xml提示,context注解提示
- Java并发包中的几种ExecutorService
- Java域隐藏、静态方法隐藏、动态绑定、静态绑定
- Java文件拆分与合并
- java.lang.IllegalStateException: Optional int parameter 'currentSpecialIndex' is present but cannot