extjs 分頁使用jsp傳遞資料樣本,extjsjsp

來源:互聯網
上載者:User

extjs 分頁使用jsp傳遞資料樣本,extjsjsp

Ext.onReady(function() {store3 = new Ext.data.JsonStore({autoDestroy: true,totalProperty : 'totle',url: 'service.do',storeId: 'myStore',root: 'data',fields : [ 'id', "name", "pw" ]});var pagingToolbar = new Ext.PagingToolbar({emptyMsg : "沒有資料",displayInfo : true,displayMsg : "顯示從{0}條資料到{1}條資料,共{2}條資料",store : store3,pageSize : 50});var grade = new Ext.grid.GridPanel({title : "資料列表",store : store3,height : 300,bbar : pagingToolbar,columns : [ {header : "id",dataIndex : "id",width : 300}, {header : "name",dataIndex : "name",width : 300}, {header : "pw",dataIndex : "pw"} ],region : 'center'});var panel = new Ext.Viewport({layout : 'border',items : [ grade ]});});

action********************

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);}

info.jsp************注意:jsp除了 @page 不能有其他的文字

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>${info}

web.xml***************

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><servlet><servlet-name>test</servlet-name><servlet-class>com.aa.TestAction</servlet-class></servlet><servlet-mapping><servlet-name>test</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>


ExtJs讀取後台資料進行分頁?

oStore = new Ext.data.JsonStore({
url: '/backend/getdata', // 這兒就是你說的後台
root: 'data',
totalProperty: 'total', // total 裡面放記錄總數
remoteSort: true,
fields: [ // 具體有哪些欄位?
'field1',
'field2',
... ...
]
});
var selModel = new Ext.grid.CheckboxSelectionModel();
var colModel = new Ext.grid.ColumnModel([selModel, {
//表格列定義
... ...
]);

oGrid = new Ext.grid.GridPanel({
title: '標題',
iconCls:'icon_xxx', // 表徵圖
ds: oStore,
cm: colModel,
sm: selModel,
loadMask: {
msg: 'Loading...'
},
tbar:[{ //頭部工具條
text: '按鈕1',
iconCls: 'icon-fileup',
tooltip: '按鈕1的動作',
handler: function(btn, e){
//
}
}],
bbar: new Ext.PagingToolbar({ //底部工具條(分頁在這兒實現)
store: oStore,
pageSize: 30, //每頁顯示的記錄數
displayInfo: true,
plugins: [new Ext.ux.PageSizePlugin()], // 這是一個外掛程式,在網上找找
emptyMsg: "沒有資料"
}),
listeners: {
render: function() {
//載入首頁資料
oStore.load({params:{start:0, limit:30}});
}
}
});

/backend/getdata 返回的資料應該是這樣
{
data: [...],
total: 100
}
 
java extjs怎實現頁面值的傳遞與接受

extjs傳參和用什麼語言做幕後處理沒關係,用以下方法傳值過去,然後用相應語言接收參數的方法正常接收就行了,
1.ajax方法傳值:
Ext.Ajax.request({
url:'DoAction.jsp?method=add',
params:{UserName:'張三',Gender:'男'},//參數列表
callback:function(options,success,response){//回呼函數
if(success){
alert(response.responseText);//返回資料
}
}
})
2.表單傳值
定義一個Ext.form.FormPanel,(後台接收參數的名稱是表單各元素的id)
var ItemForm = new Ext.form.FormPanel({.....})
然後用ItemForm.getForm().submit提交表單:
ItemForm.getForm().submit({
waitMsg:'正在儲存資料,請稍候...',
waitTitle:'提示',
method:'POST',
url:'DataAction.jsp?method=save',
params:{UserName:'張三',Gender:'男'},
success:function(form,action){
//do something here
},
failure:function(form,action){
Ext.Msg.alert('提示','儲存失敗。');
}
})
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.