<?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">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param> <listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener> <listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>RestEasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RestEasy</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping> <!-- 编码 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="lmx.phone" />
</beans>
package lmx.phone.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path; import lmx.phone.util.ExtJSResponse; import org.springframework.stereotype.Service; @Service
@Path("esper")
public class EsperService { @Path("phone")
@GET
public ExtJSResponse phoneService() {
System.out.println("rest works");
return null;
} }
package lmx.phone.util;

import java.util.HashMap;

/**
* used to integrates with ExtJS 4.x data stores.<br>
* In ExtJS, the data store use following format to verify the result:
* <p/>
* <pre>
* "{"success":false,"data":"","message":"VERBOSE ERROR"}"
* </pre>
*
* @author MiXian
*/
public class ExtJSResponse extends HashMap<String, Object> {
/**
*
*/
private static final long serialVersionUID = -2791356338016228077L; public static ExtJSResponse successRes() {
return new ExtJSResponse(true);
} public static ExtJSResponse successRes4Find(Object data,Integer total) {
ExtJSResponse res = new ExtJSResponse(true);
res.setData(data);
res.put("total",total);
return res;
} public static ExtJSResponse successResWithData(Object data) {
ExtJSResponse res = new ExtJSResponse(true);
res.setData(data);
return res;
} public static ExtJSResponse errorRes(String error) {
ExtJSResponse res = new ExtJSResponse(false);
res.setErrorMsg(error);
return res;
} public ExtJSResponse() {
} public ExtJSResponse(boolean success) {
super();
setSuccess(success);
} public boolean isSuccess() {
return (Boolean) get("success");
} public void setSuccess(boolean success) {
put("success", success);
} public void setErrorMsg(String errorMsg) {
put("error", errorMsg);
} public String getErrorMsg() {
return (String) get("error");
} public void setData(Object data) {
put("data", data);
} public Object getData() {
return get("data");
} }

关于前台和后台之间的交互:

1、extjs发送ajax请求,以“/rest/*”的形式。

2、web.xml捕捉到请求之后,将请求发给DispatherServlet

3、DispatherServlet将请求发给配置的package

4、package扫描所有的“@service”类,寻找匹配的方法来处理请求,并返回给前端一个json数据串。json数据串通过ExtjsResonse来生成一个基本的内容。

5、前端根据json数据串来改变前端的内容

关于spring和extjs对接的过程简述的更多相关文章

  1. 工厂模式模拟Spring的bean加载过程

    一.前言    在日常的开发过程,经常使用或碰到的设计模式有代理.工厂.单例.反射模式等等.下面就对工厂模式模拟spring的bean加载过程进行解析,如果对工厂模式不熟悉的,具体可以先去学习一下工厂 ...

  2. Spring之IOC容器初始化过程

    Ioc容器的初始化是由refresh()方法来启动的,这个方法标志着Ioc容器的正式启动. 具体来说这个启动过程包括三个基本过程: 1.BeanDifinition的Resource定位 2.Bean ...

  3. 升级到 ExtJS 5的过程记录

    升级到 ExtJS 5的过程记录   最近为公司的一个项目创建了一个 ExtJS 5 的分支,顺便记录一下升级到 ExtJS 5 所遇到的问题以及填掉的坑.由于 Sencha Cmd 的 sencha ...

  4. spring internalTransactionAdvisor 事务 advisor 初始化过程

    spring internalTransactionAdvisor 事务 advisor 初始化过程:

  5. Spring容器的创建刷新过程

    Spring容器的创建刷新过程 以AnnotionConfigApplicationContext为例,在new一个AnnotionConfigApplicationContext的时候,其构造函数内 ...

  6. Spring IOC容器创建bean过程浅析

    1. 背景 Spring框架本身非常庞大,源码阅读可以从Spring IOC容器的实现开始一点点了解.然而即便是IOC容器,代码仍然是非常多,短时间内全部精读完并不现实 本文分析比较浅,而完整的IOC ...

  7. Spring Security 解析(二) —— 认证过程

    Spring Security 解析(二) -- 认证过程   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...

  8. Spring Security 解析(一) —— 授权过程

    Spring Security 解析(一) -- 授权过程   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...

  9. Spring Bean 的加载过程

    Spring Bean 的加载过程 一个是populateBean,一个是initializeBean,这两个方法完成了bean的赋值与初始化. 这里有一个BeanDefinitionValueRes ...

随机推荐

  1. 在windows系统下虚拟机和ubuntu系统的安装和卸载

    一.安装 之前有装过双系统,但是吧,一直用ubuntu系统,很久没进windows之后的某一天,自己再进windows,发现windows系统崩了,我也不知道为什么,找了很多方法没有解决,最后只好重装 ...

  2. jQuery中事件模块介绍

    事件模块 1.提供其他DOM方法 包括:next 和 nextAll方法 1.1 next方法实现 目标:扩展框架方法,获取当前元素的下一个元素 问题:如何获取下一个元素? 1.1.1 提供 next ...

  3. SqlServer与MySql 系统表查询自建表数据

    SqlServer: SELECT * FROM sys.sysobjects WHERE type='U' ORDER BY name SELECT * FROM sys.syscolumns WH ...

  4. 软件开发的MVC构架

    MVC:IDE开发环境开发时,无意中使用的软件结构. 转自于wikipedia:http://zh.wikipedia.org/wiki/MVC 软件的层次划分:框架--组件(设计模式)--算法与数据 ...

  5. -1.#IND000 &&图像类型转换

    (1):float acos(float x) 参数x的范围为-1.0f到1.0f之间,返回值范围在0.0f到3.141592653f之间,值得注意的是:当x超出[-1.0f,1.0f]这个范围时此函 ...

  6. 基于MapReduce的贝叶斯网络算法研究参考文献

    原文链接(系列):http://blog.csdn.net/XuanZuoNuo/article/details/10472219 论文: 加速贝叶斯网络:Accelerating Bayesian ...

  7. PHP 获取文件 扩展名 的常用方法小结【五种方式】

      1: function getExt1($filename) {     $arr = explode('.',$filename);     return array_pop($arr);; } ...

  8. 初级模拟电路:1-2 PN结与二极管

    回到目录 1.   掺杂半导体 上面我们分析了本征半导体的导电情况,但由于本征半导体的导电能力很低,没什么太大用处.所以,一般我们会对本征半导体材料进行掺杂,即使只添加了千分之一的杂质,也足以改变半导 ...

  9. timeval的时间转换成毫秒之后多大的数据类型可以装下

    struct timeval { long tv_sec; /*秒*/ long tv_usec; /*微秒*/ }; 秒的定义为long,为了防止溢出,转换成毫秒之后保存在long long中

  10. jmeter图片的下载

    1.jmeter下载文件 首先添加一个线程组,然后在线程组里面添加一个http请求,因为是获取数据,所有是get请求,写好下载的地址 1.添加线程组 :右键测试计划,添加-Threads(Users) ...