yui ----autocomplete 的一个问题(大虾请进)

daiqiaobin 2007-11-03 01:20:59
偶正要用yui做开发
服务器端:

AutoComp.java-------------------------------

package ajaxdemo1;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class AutoComp extends HttpServlet {
private static final String CONTENT_TYPE = "text/xml; charset=UTF-8";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
//务必清空页面缓存
response.addHeader("Cache-Control","no-cache");

System.out.println("url = " + request.getRequestURL() + "?" + request.getQueryString());
String query = request.getParameter("query");

PrintWriter out = response.getWriter();
out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.print("<Resultset>");
for(int i=0;i<40;i++){
out.print("<Result>");
out.print("<Title>title"+i+"</Title>");
out.print("<Summary>Hello World"+i+"!</Summary>");
out.print("</Result>");
}
out.print("</Resultset>");
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}

index.jsp================================

<%@ page contentType="text/html; charset=GBK" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX测试文件</title>

<link rel="stylesheet" type="text/css" href="build/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="build/autocomplete/assets/skins/sam/autocomplete.css" />
<script type="text/javascript" src="build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="build/animation/animation.js"></script>
<script type="text/javascript" src="build/autocomplete/autocomplete.js"></script>
<script type="text/javascript" src="build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="build/event/event.js"></script>
<script type="text/javascript" src="build/connection/connection.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
#ysearchautocomplete{
margin-bottom:2em;
width:25em;
}
</style>

</head>
<body class="yui-skin-sam">

<form action="http://localhost:8080/ajax" onsubmit="return YAHOO.example.ACXml.validateForm();">
<h3>Yahoo! Search:</h3>
<div id="ysearchautocomplete">
<input id="ysearchinput" type="text" name="p">
<div id="ysearchcontainer"></div>
</div>
</form>

<script type="text/javascript" >
YAHOO.example.ACXml = new function(){

// Instantiate an XHR DataSource and define schema as an array:
// ["Multi-depth.object.notation.to.find.a.single.result.item",
// "Query Key",
// "Additional Param Name 1",
// ...
// "Additional Param Name n"]

this.oACDS = new YAHOO.widget.DS_XHR("http://localhost:8080/ajax/autocomp", ["Result", "Title", "Summary"]);
this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_XML;
//this.oACDS.queryMatchContains = true;
//this.oACDS.scriptQueryAppend = ""; // Needed for YWS
// Instantiate AutoComplete

this.oAutoComp = new YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", this.oACDS);

// Display up to 20 results in the container
this.oAutoComp.maxResultsDisplayed = 10;

// Require user to type at least 1 characters before triggering a query
this.oAutoComp.minQueryLength = 1;

// Every key input event will trigger an immediate query...
this.oAutoComp.queryDelay = 0;

// ...or queries will be sent after 3 seconds have passed
// since the last key input event
//this.oAutoComp.queryDelay = 3;
// Do not automatically highlight the first result item in the container
this.oAutoComp.autoHighlight = false;

// Enable a drop-shadow under the container element
this.oAutoComp.useShadow = true;

// Enable an iFrame shim under the container element
this.oAutoComp.useIFrame = true;

this.oAutoComp.formatResult = function(oResultItem, sQuery) {
return oResultItem[0] + " " + oResultItem[1];
};


// Stub for AutoComplete form validation
this.validateForm = function() {
// Validation code goes here
return true;

};

};
</script>

</body>
</html>


以上代码报错:
this.connMgr 为空或不是对象
请问是怎么回事啊?
...全文
167 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveyt 2007-11-05
  • 打赏
  • 举报
回复
你那是JS吧......错误不在Servlet里面.页面上要引入Yahoo!的JS Libiary.
daiqiaobin 2007-11-04
  • 打赏
  • 举报
回复
new YAHOO.widget.DS_XHR( "http://localhost:8080/ajax/autocomp ", [ "Result ", "Title ", "Summary "]);

就是上面这句报错
其中YAHOO.widget.DS_XHR("....","...")
此方法调用了YaHoo UI 库中的函数
函数中有this.connMgr对象
我想YaHoo UI 库是不会有错的,只是我不知道这个方法怎么用
daiqiaobin 2007-11-04
  • 打赏
  • 举报
回复
是雅虎的YUI控件库的对象
FredWorks 2007-11-03
  • 打赏
  • 举报
回复
你贴出来的代码从头到尾,就没有出现过connMgr...

81,092

社区成员

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

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