唉,如果有人能把这个问题帮我搞定就好了,先谢谢大家了

yaolilili 2007-08-02 05:22:23
今天买了:<<Ajax基础教程>>一书,是"人民邮电出版社出版"的.金灵翻译的.
其中的用来接收ajax传递过来用的是javaservlet但是我用javac编译javaservlet源程序的时候,提示找不到类,我在java的API上也检查了,也查不到它所要求导入的类,请问这是为什么啊?源文件如下:不会是书上印刷错误了吧?(书上的每个sevelet程序都导入了同样的类,也不可能搞错吧,
毕竟这么大的一个出版社吗?:::::::::::::::)
package ajaxbook.chap3;

import java.io.*;
import javax.servlet.*;//提示找不到这个类,到底是为什么啊?
import javax.servlet.http.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class PostingXMLExample extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String xml = readXMLFromRequestBody(request);
Document xmlDoc = null;
try {
xmlDoc =
DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new ByteArrayInputStream(xml.getBytes()));
}
catch(ParserConfigurationException e) {
System.out.println("ParserConfigurationException: " + e);
}
catch(SAXException e) {
System.out.println("SAXException: " + e);
}

/* Note how the Java implementation of the W3C DOM has the same methods
* as the JavaScript implementation, such as getElementsByTagName and
* getNodeValue.
*/
NodeList selectedPetTypes = xmlDoc.getElementsByTagName("type");
String type = null;
String responseText = "Selected Pets: ";
for(int i = 0; i < selectedPetTypes.getLength(); i++) {
type = selectedPetTypes.item(i).getFirstChild().getNodeValue();
responseText = responseText + " " + type;
}

response.setContentType("text/xml");
response.getWriter().print(responseText);
}

private String readXMLFromRequestBody(HttpServletRequest request){
StringBuffer xml = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while((line = reader.readLine()) != null) {
xml.append(line);
}
}
catch(Exception e) {
System.out.println("Error reading XML: " + e.toString());
}
return xml.toString();
}
}
...全文
178 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaolilili 2007-08-02
  • 打赏
  • 举报
回复
哦,多谢你了:redbugler(红色号手)
你是我遇到的最能解决问题的一下,分一定给人,明天给,现在网速跟不上,
先谢谢你了
再次超越梦想 2007-08-02
  • 打赏
  • 举报
回复
搞ASP當然不知道這個了。你需要Java實現的web容器(就是web server),簡單的就用Tomcat好了。它的Lib裏就有你需要的東西。
yaolilili 2007-08-02
  • 打赏
  • 举报
回复
不好意思,我不是学java的是搞asp的用到ajax,但是ajax用处理程序用的是java所以........

最后想请教一下,如何导入“servlet-api.jar”
?多谢高人赐教
kingdom_seu 2007-08-02
  • 打赏
  • 举报
回复
Thinking in java
sureyor 2007-08-02
  • 打赏
  • 举报
回复
爆汗-_-!!,现在的人都是不学走,直接在飞呀...
aspirerME 2007-08-02
  • 打赏
  • 举报
回复
因为你没有导入“servlet-api.jar”

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧