首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

ExtJS与Struts 二框架整合

2014-01-23 
ExtJS与Struts 2框架整合一、 XML与JSON的生成package com.ibeifeng.xstreampackage com.ibeifeng.jsonlib

ExtJS与Struts 2框架整合

一、 XML与JSON的生成

package com.ibeifeng.xstream;

package com.ibeifeng.jsonlib;

?

import net.sf.json.JSONObject;

?

import com.ibeifeng.xstream.Person;

?

publicclass TestJsonlib {

?? publicstaticvoid main(String[] args) {

????? Person person = new Person();

????? person.setName("张三");

????? person.setAge(20);

????? person.setSex(true);

????? JSONObject jsonObject = JSONObject.fromObject(person);

????? System.out.println(jsonObject.toString());

?? }

}

?

package com.ibeifeng.jsonlib;

?

import java.util.ArrayList;

import java.util.List;

?

import net.sf.json.JSONArray;

?

import com.ibeifeng.xstream.Person;

?

publicclass TestJsonlibList {

?? publicstaticvoid main(String[] args) {

????? List<Person> persons = new ArrayList<Person>();

????? Person person1 = new Person();

????? person1.setName("张三");

????? person1.setAge(20);

????? person1.setSex(true);

?????

????? Person person2 = new Person();

????? person2.setName("李四");

????? person2.setAge(30);

????? person2.setSex(false);

?????

????? persons.add(person1);

????? persons.add(person2);

?????

????? JSONArray jsonObjects = JSONArray.fromObject(persons);

????? System.out.println(jsonObjects.toString());

?? }

}

?

?

????? ? <!--定义核心Filter FilterDispatcher -->

????? <filter>

???????? <!-- 定义核心Filter的名称 -->

???????? <filter-name>struts2</filter-name>

???????? <!--定义核心Filter的实现类 -->

???????? <filter-class>

??????????? org.apache.struts2.dispatcher.FilterDispatcher

???????? </filter-class>

????? </filter>

?????

????? <filter-mapping>

???????? <!--核心Filter的名称 -->

???????? <filter-name>struts2</filter-name>

???????? <!--使用该核心Filter来接受所有的Web请求 -->

???????? <url-pattern>/*</url-pattern>

????? </filter-mapping>

package com.ibeifeng.action;

?

import java.util.ArrayList;

import java.util.List;

?

import com.ibeifeng.xstream.Person;

import com.opensymphony.xwork2.ActionSupport;

?

publicclass GetPerson extends ActionSupport {

?? List<Person> persons;

??

?? public List<Person> getPersons() {

????? returnpersons;

?? }

?

?? publicvoid setPersons(List<Person> persons) {

????? this.persons = persons;

?? }

?

?? publicString execute() throws Exception {

????? persons = new ArrayList<Person>();

????? Person person1 = new Person();

????? person1.setName("张三");

????? person1.setAge(20);

????? person1.setSex(true);

?????

????? Person person2 = new Person();

????? person2.setName("李四");

????? person2.setAge(30);

????? person2.setSex(false);

?????

????? persons.add(person1);

????? persons.add(person2);

????? returnSUCCESS;

?? }

??

}

?

<?xml version="1.0" encoding="UTF-8" ?>

?

<!DOCTYPE struts PUBLIC

??? "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

??? "http://struts.apache.org/dtds/struts-2.0.dtd">

?

<struts>

??

?? <package name="struts2" extends="json-default">

????? <action name="getPerson" class="com.ibeifeng.action.GetPerson">

???????? <result type="json"/>

????? </action>

?? </package>

</struts>

?

热点排行