当前位置: 代码迷 >> Java Web开发 >> 各位大神帮小弟我看看关键字查询有关问题,多谢!
  详细解决方案

各位大神帮小弟我看看关键字查询有关问题,多谢!

热度:719   发布时间:2016-04-14 21:23:38.0
各位大神帮我看看关键字查询问题,谢谢!!
<div class="siteSearch">
<a href="javascript:gSearch()" class="searchBtn"></a>
<input type="text" maxlength="50" name="keyWord" value="请输入搜索关键字" onfocus="this.value=&#39;&#39;;this.style.color=&#39;#333&#39;">
</div>

<script type="text/javascript">
if( ''!='' ){ document.getElementById('keyWord').value=''; }
document.getElementById("keyWord").onkeydown=function(e){
 e = e || window.event;
if(e.keyCode==13) {gSearch();}
}

function gSearch(){
var keyword = document.getElementById('keyWord').value;
if(keyword=='' || keyword=="请输入搜索关键字"){ alert("请输入搜索关键字"); }
else{
window.location = "search.do?command=blurQuery&keyword=keyword;
}
}
</script></div>


public ActionForward blurQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 获取类索引和关键词

String keyWord = request.getParameter("keyword");
// 获取当前页
String currPage = request.getParameter("currPage");
String hql = "from Info d ";
Object[] where = null;
String action = request.getContextPath() + "/search.do?command=blurQuery";
// 转码
if (currPage != null && !currPage.isEmpty()) {
keyWord = StringUtil.encodeZh(keyWord);
}

if (keyWord != null && !keyWord.isEmpty()) {
action += "&keyWord=" + StringUtil.encodeURL(keyWord);
keyWord = "%" + keyWord + "%";
hql += " where d.title like ? ";
where = new Object[] {keyWord};

}
// 分页查询
Map map = this.getPage(hql, recPerPage, currPage, action, where);
//将结果集放到request中
request.setAttribute("list", map.get("list"));
//将结果集放到分页条中
request.setAttribute("pagingBar", map.get("bar"));

return mapping.findForward("findAllSuccess");
}


运行显示错误:
javax.servlet.jsp.JspException: Cannot find bean: "list" in scope: "request"
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:937)
at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:232)
at org.apache.jsp.search_jsp._jspService(search_jsp.java:148)

........
是不是错在 window.location = "search.do?command=blurQuery&keyword=keyword;
怎么解决?谢谢!!
------解决思路----------------------
你这个关键字查询是提交一个form表单么?如果是的话,那就肯定会出错了,如果你用location.href或者window.location.href,这不是提交表单,这是重定向,jquery提交表单是:
$("form").attr("action","../PublishPost.action").submit();


------解决思路----------------------
引用:
你这个关键字查询是提交一个form表单么?如果是的话,那就肯定会出错了,如果你用location.href或者window.location.href,这不是提交表单,这是重定向,jquery提交表单是:
$("form").attr("action","../PublishPost.action").submit();

额,忘了说了,你这个是一个div,不是form表单,顺便把div改成form表单
------解决思路----------------------
你的JSP代码中有错误了吧
javax.servlet.jsp.JspException: Cannot find bean: "list" in scope: "request"
这个错误的意思是,你尝试在JSP页面中使用名字叫list的Bean,但是这个Bean不存在
是不是JSP页面少做了非空的判断呀
  相关解决方案