关于jsp中的Unable to compile class for JSP解决

本文记录了一个AJAX项目中使用XML时遇到的解析异常问题及解决过程。作者在使用XPPReader读取XML时遇到了类型未解析和方法引用丢失的问题,并尝试通过添加pull-parser-2.1.10.jar包来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在一个ajax项目中引用了xml,在写到
Document xmlDoc = (Document)new XPPReader().read(new ByteArrayInputStream(xml.getBytes()));
的时候,出现

  1. Multiple annotations found at this line:  
  2.     - The type org.gjt.xpp.XmlPullParserException cannot be resolved. It is indirectly referenced from   
  3.      required .class files  
  4.     - The method read(InputStream) from the type XPPReader refers to the missing type XmlPullParserException  
  5.     - The type org.gjt.xpp.XmlPullParserException cannot be resolved. It is indirectly referenced from   
  6.      required .class files  
  7.     - The method read(InputStream) from the type XPPReader refers to the missing type XmlPullParserException  
然后百度了一下,说是要加载 pull-parser-2.1.10.jar包,于是我把这个包加到工程中,同时在jsp开头包含进对应的类
<%@page import="org.gjt.xpp.*"%>
然后这错误也就不见了
jsp写完了,开开心心启动程序,一运行,结果又开始出现错误,还是一样的错误,想必刚刚是指标不治本。

查看异常说明,看到这样一句
Unable to compile class for JSP
怎么会不能编译呢,于是又百度,这次是说把工程下的servlet-api.jar和jsp.api.jar删除掉
我找了一下,我的工程只有servlet-api.jar,没有jsp.api.jar,我把servlet-api.jar删掉了,但是一删掉,工程中引用了这个包的类全都报错

显然这个方法行不通,于是我又把这个包添加回来。

上次写到一半,现在忘记具体细节了,只记得是要把servlet-api.jar放到工程的lib下,不能放在工程外面。应该是程序运行的时候,在lib下查找对应的类吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值