The project to use the SOLR search engine, enter the characters in the input box, want to do similar to Baidu effect, drop-down box appears 10 suggested entries, for this, with the jquery UI Autocomplete do auto-completion
Examples of JSP pages:
<%@ page language= "java" contenttype= "Text/html;charset=utf-8" pageencoding= "UTF-8"% ><%@ include file= "/web-inf/views/include.jsp" %>Action class:
Package cn.sniper.springmvc.action;import java.util.arraylist;import java.util.list;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.requestmapping;import org.springframework.web.bind.annotation.responsebody;import cn.sniper.springmvc.po.address;@ Controller@requestmapping ("/demoaction") public class demoaction { @RequestMapping ("/ Suggestion.action ") public string suggestion () { return "/demo/demod "; } /** * ajax Request Call * @return */ @RequestMapping ("/getsuggestions.action") public @ResponseBody list<address> getsuggestions (String address, integer max) { list<address> addresslist = new ArrayList<Address> (); addresslist.add (New address (1l, "admin-1")); addresslist.add (nEw address (2l, "admin-2")); return addresslist; } }
MVC configuration file:
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "http://www.springframework.org/ Schema/beans " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns:mvc="/HTTP/ Www.springframework.org/schema/mvc " xmlns:context=" Http://www.springframework.org/schema/context " xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:p= "http://www.springframework.org/schema/p" xsi:schemalocation= "http// www.springframework.org/schema/beans http://www.springframework.org/ schema/beans/spring-beans-3.0.xsd http://www.springframework.org/ Schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/ schema/aop http://www.springframework.org/schema/aop/ spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> <mvc:annotation-driven /> <!-- Component Scan --> <context: Component-scan base-package= "Cn.sniper.springmvc.action" ></context:component-scan> <bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" value= "/web-inf/views/" ></property> <property name= " Suffix " value=". JSP "></property> </bean></beans>
Xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.4" xmlns= "/http Java.sun.com/xml/ns/j2ee " xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " xsi: schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > <!-- Configuration Springmvc start Dispatcherservlete entry --> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring/springmvc.xml</param-value> </init-param> < load-on-startup>1</load-on-startup> </servlet> < servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
Maven configuration file Pom.xml
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/maven-v4_0_0.xsd "> <modelVersion>4.0.0</modelVersion> <groupId>cn.sniper.springmvc</groupId> <artifactId>springmvc</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>springmvc maven webapp</name> <url>http:// maven.apache.org</url> <properties> < project.build.sourceencoding>utf-8</project.build.sourceencoding> <spring.version>3.1.1. release</spring.version> <struts.version>2.3.4.1</struts.version> < Hibernate.version>3.6.9.finalJQuery UI AutoComplete Auto-complete