Directory
Effect:
Extjs code:
Ext. onReady (function () {// var data = [{// name: 'tang bohu ', // age: 25, // sex: 'male '//}, {// name: 'chu Liuxiang ', // age: 24, // sex: 'female' //}]; var ds = new Ext. data. jsonStore ({proxy: new Ext. data. httpProxy ({url: 'studentaction _ findlist '// relative path}), root: '', fields: [{name: 'id'}, {name: 'name'}, {name: 'sex '}, {name: 'age'}, {name: 'phone'}, {name: 'address'}, {name: 'birthday'}]}); // ds. loadData (data); var grid = new Ext. grid. gridPanel ({viewConfig: {forceFit: true}, store: ds, columns: [{header: 'number', dataIndex: 'id'}, {header: 'name ', dataIndex: 'name'}, {header: 'gender ', dataIndex: 'sex'}, {header: 'birthdate', renderer: Ext. util. format. dateRenderer ("m y, month, day"), dataIndex: 'birthday'}, {header: 'mobile phone no. ', dataIndex: 'phone'}, {header: 'address ', dataIndex: 'address'}, {header: 'age', dataIndex: 'age'}]}); var win = new Ext. window ({title: 'httpproxy', width: 900, height: 300, layout: 'fit ', items: grid}); ds. load (); win. show ();});
Action:
Package com. ext. action; import java. io. IOException; import java. io. unsupportedEncodingException; import java. SQL. SQLException; import java. util. arrayList; import java. util. list; import java. util. map; import net. sf. json. JSONArray; import org. apache. struts2.ServletActionContext; import org. springframework. jdbc. core. jdbcTemplate; import com. ext. pojo. student; import com. opensymphony. xwork2.ActionSupport; public class StudentAction extends ActionSupport {/*****/private static final long serialVersionUID = 1L; public JdbcTemplate getJdbcTemplate () {return jdbcTemplate;} public void Merge (JdbcTemplate jdbcTemplate) {this. jdbcTemplate = jdbcTemplate;} private JdbcTemplate jdbcTemplate; public void findlist () {ServletActionContext. getResponse (). setCharacterEncoding ("UTF-8"); try {ServletActionContext. getRequest (). setCharacterEncoding ("UTF-8");} catch (UnsupportedEncodingException e1) {// TODO Auto-generated catch blocke1.printStackTrace ();} try {System. out. println ("************************************* * ********** = "+ jdbcTemplate. getDataSource (). getConnection ();} catch (SQLException e) {// TODO Auto-generated catch blocke. printStackTrace ();} String json = "[{"; List t_list = jdbcTemplate. queryForList ("select * from student;"); for (int I = 0; I
Spring configuration file:
Xmlns: context = "http://www.springframework.org/schema/context"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation ="
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
">
Destroy-method = "close"
Name = "MydataSource">
Com. mysql. jdbc. Driver
Jdbc: mysql: // localhost: 3306/test
Root
123
Struts. xml
/WEB-INF/JspPage/chapter1/HelloWorld.jsp
Web. xml
ExtJsApplication
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
WEB-INF/Spring*.xml
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
Pojo:
Package com. ext. pojo;
Import java. SQL. Timestamp;
Public class student {
Private int id;
Private String name;
Private int sex;
Private int age;
Private String phone;
Private Timestamp birthday;
Private String address;
// Optional course number
Private int courseId;
Public int getId (){
Return id;
}
Public void setId (int id ){
This. id = id;
}
Public String getName (){
Return name;
}
Public void setName (String name ){
This. name = name;
}
Public int getAge (){
Return age;
}
Public void setAge (int age ){
This. age = age;
}
Public String getPhone (){
Return phone;
}
Public void setPhone (String phone ){
This. phone = phone;
}
Public String getAddress (){
Return address;
}
Public void setAddress (String address ){
This. address = address;
}
Public Timestamp getBirthday (){
Return birthday;
}
Public void setBirthday (Timestamp birthday ){
This. birthday = birthday;
}
Public int getCourseId (){
Return courseId;
}
Public void setCourseId (int courseId ){
This. courseId = courseId;
}
Public int getSex (){
Return sex;
}
Public void setSex (int sex ){
This. sex = sex;
}
}
Index.html:
extjs
<script type="text/javascript" src="js/ext-all.js"></script><script type="text/javascript" src="js/application.js"></script>