没有servlet-api编译不了servlet

      在windows7系统下用MyEclipse写Servlet代码当然简便,不过我今天想用一下命令行来编译,谁知道离开了强大的编辑软件,手动编译就出现了不少Exception。

      假设工程安装在C:\Users\Bobo\webTest\MailWebTest目录下,在MailWebTest\WebRoot\WEB-INF\classes下有一个Servlet类MsgInfo.java,如何用命令行编译MsgInfo.java呢?

      首先把光标定位在MsgInfo.java所在目录上,敲代码"javac MsgInfo.java",结果都报一大堆异常:

MsgInfo.java:10: 软件包 javax.servlet 不存在
import javax.servlet.ServletException;
                    ^
MsgInfo.java:11: 软件包 javax.servlet.http 不存在
import javax.servlet.http.HttpServlet;
                         ^
MsgInfo.java:12: 软件包 javax.servlet.http 不存在
import javax.servlet.http.HttpServletRequest;
                         ^
MsgInfo.java:13: 软件包 javax.servlet.http 不存在
import javax.servlet.http.HttpServletResponse;
                         ^
MsgInfo.java:16: 找不到符号
符号: 类 HttpServlet
public class MsgInfo extends HttpServlet {
                             ^
MsgInfo.java:19: 找不到符号
符号: 类 HttpServletRequest
位置: 类 MsgInfo
        public void doGet(HttpServletRequest request, HttpServletResponse respon
se)
                          ^
MsgInfo.java:19: 找不到符号
符号: 类 HttpServletResponse
位置: 类 MsgInfo
        public void doGet(HttpServletRequest request, HttpServletResponse respon
se)
                                                      ^
MsgInfo.java:20: 找不到符号
符号: 类 ServletException
位置: 类 MsgInfo
                        throws ServletException, IOException {
                               ^
MsgInfo.java:62: 找不到符号
符号: 类 HttpServletRequest
位置: 类 MsgInfo
        public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
                           ^
MsgInfo.java:62: 找不到符号
符号: 类 HttpServletResponse
位置: 类 MsgInfo
        public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
                                                       ^
MsgInfo.java:63: 找不到符号
符号: 类 ServletException
位置: 类 MsgInfo
                        throws ServletException, IOException {
                               ^
MsgInfo.java:55: 找不到符号
符号: 方法 getClass()
位置: 类 MsgInfo
                out.print(this.getClass());
                              ^
12 错误

 

      其实问题就只有一个,就是没有servlet的包,那么这个包哪里可以找呢?Tomcat本身就有了。如果机器本身安装了Tomcat的话,就在Tomcat x.x\lib里面有servlet-api.jar包,只要把这个复制到Java\jre\lib\ext文件夹,就可以编译通过了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值