日期:2014-05-16  浏览次数:20370 次

基于prototype.js和spring的ajax分页
这是一个基于prototype.js的ajax分页,运用了spring框架,自定义分页标签,每次进入列表页面时,把列表存入session,分页只对session存储的列表进行分页,不需要再去查询数据库。但在数据量十分大的情况下,没有做性能测试。

首先在web.xml中配置spring监听和servlet

web.xml内容如下:
# <?xml version="1.0" encoding="UTF-8"?>  
# <web-app version="2.5"   
#     xmlns="http://java.sun.com/xml/ns/javaee"   
#     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
#     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
#     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
#   
#   
#   <context-param>  
#     <param-name>contextConfigLocation</param-name>  
#     <param-value>classpath*:com/kt/application/application-context.xml</param-value>  
#   </context-param>  
#   
#   <listener>  
#     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
#   </listener>  
#   
#   <servlet>  
#     <servlet-name>root-dispatcher</servlet-name>  
#     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
#     <load-on-startup>1</load-on-startup>  
#   </servlet>  
#   
#   <servlet-mapping>  
#     <servlet-name>root-dispatcher</servlet-name>  
#     <url-pattern>*.do</url-pattern>  
#   </servlet-mapping>  
#   
#   <welcome-file-list>  
#     <welcome-file>index.jsp</welcome-file>  
#   </welcome-file-list>  
# </web-app> 


还需要在WEB-INF下建个root-dispatcher-servlet.xml的文件(没有这个文件会报错,为什么少了这个会出错就不知道了)

root-dispatcher-servlet.xml内容如下:
# <?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:util="http://www.springframework.org/schema/util"  
#     xmlns:lang="http://www.springframework.org/schema/lang"  
#     xmlns:aop="http://www.springframework.org/schema/aop"  
#     xmlns:tx="http://www.springframework.org/schema/tx"  
#     xsi:schemaLocation="  
#         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
#         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd  
#         http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd  
#         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd  
#         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">  
#   
# </beans>


下面是spring的配置文件,文件名是application-context.xml(为了方便spring的配置都写这个文件里了),启动tomcat 的时候加载

application-context.xml 内容如下
# <?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:util="http://www.springframework.org/schema/util"  
#     xmlns:lang="http://www.springframework.org/schema/lang"  
#     xmlns:aop="http://www.springframework.org/schema/aop"  
#     xmlns:tx="http://www.springframework.org/schema/tx"  
#     xsi:schemaLocation="  
#         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
#         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd  
#         http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd  
#         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd  
#         http://www.springframework.org/schema/aop http://www.springfra