展示了ExtJS分页组件与JSP后端的数据传递流程:前端利用JsonStore和PagingToolbar构建分页网格,后端Servlet生成JSON字符串并转发至JSP页面输出。关键实现要点是JSP中仅保留@page指令,避免多余字符以确保JSON正确解析。
ExtJS分页示例:使用JSP传递数据
作者:技术拾光
时间:2026-06-11
浏览:227
文章目录
在前端开发中,ExtJS 的分页组件配合 JSP 后端传递数据是一种常见需求。以下通过一个完整示例展示从前端网格搭建、后端 Servlet 数据处理到 JSP 页面响应输出的完整流程,实际项目中可直接套用该模式。
test
com.aa.TestAction
test
*.do
index.jsp
```
整套流程完成后,前端分页组件即可正常获取数据并展示。实际部署时需注意:JSP 页面除
前端代码:ExtJS 分页网格
```html ```action********************
后端 Servlet 处理
后端 Servlet 模拟生成 50 条数据,拼接成 JSON 字符串后通过 request 转发给 JSP 输出。 ```java protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List list = new ArrayList(); for (int i = 0; i < 50; i++) { Person p = new Person(); p.setId("id" + i); p.setName("name" + i); p.setPw("pw" + i); list.add(p); } StringBuffer info = new StringBuffer(); info.append("{totle:2000,data:"); info.append(JSONArray.fromObject(list)); info.append("}"); System.out.println(info.toString()); System.out.println("*****doPos"); request.setAttribute("info", info.toString()); request.getRequestDispatcher("/info.jsp").forward(request, response); } ```JSP 输出页面
info.jsp************注意:jsp除了 @page 不能有其他的文字
```jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> ${info} ```web.xml 配置
将 Servlet 映射到*.do 后缀的请求上。
```xml
@page 指令外不应包含任何多余字符,否则会导致 JSON 解析错误。实用工具推荐
电子包浆
使用 ›绿化、压缩、噪点和虚拟水印,自由调节做旧程度。
图片压缩
使用 ›选择画质和输出格式,预览压缩前后的大小。
相关文章