JQ仿百度提示页面
来源:互联网 发布:手机淘宝5.7.2版本苹果 编辑:程序博客网 时间:2024/05/22 07:55
代码实现
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>My JSP 'search.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript" src="jquery-3.2.1.js"></script></head><script type="text/javascript">$(function() {$("#word").keyup(function() {/* 获得文本框的值 */var word = $("#word").val();/* 异步发送请求 */if (word != "") {$.post("/J2EE/searchservlet", {"word" : word}, function(data) {$("#d1").show().html(data);});} else {$("#d1").hide();}});});</script><body><center><h1>百度一下</h1><input type="text" name="word" id="word"style="width: 400px;height: 25px" /><input type="button"value="百度一下" /> <br><span id="d1"></span></center></body></html>
package search;import java.io.IOException;import java.io.PrintWriter;import java.sql.SQLException;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class searchservlet extends HttpServlet {/** * 仿百度搜索页面 */private static final long serialVersionUID = 1L;public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("UTF-8");//解决post提交中文乱码response.setContentType("UTF-8");//解决页面输出中文乱码String word=request.getParameter("word");wordservice ws=new wordservice();try {List<Words> words=ws.search(word);request.setAttribute("words", words);request.getRequestDispatcher("/html/info.jsp").forward(request, response);//牢记转发时不要带工程名} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet( request, response);}}
package search;public class Words {private int id;private String word;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getWord() {return word;}public void setWord(String word) {this.word = word;}}
package search;import java.sql.SQLException;import java.util.List;public class wordservice {public List<Words> search(String word) throws SQLException {// TODO Auto-generated method stubworddao wd=new worddao();return wd.search(word);}}
package search;import java.sql.SQLException;import java.util.List;import org.apache.commons.dbutils.QueryRunner;import org.apache.commons.dbutils.handlers.BeanListHandler;import utils.c3p0tool;public class worddao {public List<Words> search(String word) throws SQLException {// TODO Auto-generated method stubQueryRunner qr=new QueryRunner(c3p0tool.getDataSource());/*String sql1="insert into words values(null,?)";qr.update(sql1,word);*/String sql="select * from words where word like ? limit 2";/*只查两个*/List<Words> l = qr.query(sql,new BeanListHandler<Words>(Words.class),word+"%");for(Words i:l){String sql1="insert into words values(null,?)";qr.update(sql1,i.getWord());}return l;}}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><table><c:forEach items="${words}" var="w"><tr><td>${w.word}</td></tr></c:forEach></table>
阅读全文
0 0
- JQ仿百度提示页面
- 仿百度注册页面
- 仿百度页面
- 用jq实现仿百度搜索框
- 仿百度的自动提示
- 仿百度智能导诊页面
- 仿百度ajax搜索提示(jsp)
- 仿百度的搜索下拉提示
- 仿百度的智能提示功能
- 仿百度和google的搜索提示
- 仿百度搜索下拉提示功能
- 仿百度下拉提示框代码
- JQUERY仿百度谷歌智能提示
- 仿百度搜索自动提示技术
- 仿百度智能提示搜索框
- easyui仿百度搜索提示框
- 类似百度搜索提示效果(asp.net+JQ+Ajax)
- 仿百度页面(html+css)
- 推荐个软件EveryThing(可以快速找到电脑里的各种东西)
- MYsql中的数据带,如何处理
- 全方位立体化智能监控平台建设经验
- spring boot druid多数据源的yml配置
- Retrofit自定义Converter步骤
- JQ仿百度提示页面
- python3 爬虫入门(二)requests库基本使用
- 拆书《一生的计划》活动记录
- vsftpd配置文件详解
- 升级Node.js报错
- java static 修饰符
- 云星数据---Scala实战系列(精品版)】:Scala入门教程042-Scala实战源码-Scala 集合List
- MVC模式(三层架构模式)
- Voxel Space:不到20行代码实现地形渲染