<?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. css简单介绍

    css层叠样式表,主要作用就是解决内容与表现分离的问题.html标签有自己的意义当然也是有自己的默认样式的,但有时候我们想修改他的样式,这时候就需要了css. 例:给字体加上颜色,我们有如下几种方法: ...

  2. RN打包的那些坑儿

    Write By lz: Lz 寄语: RN虐我千百遍, 我待RN如初恋, 坑儿爬多了也就自然了 官方文档: http://reactnative.cn/docs/0.43/signed-apk-an ...

  3. 如何拿到阿里算法校招offer

    好多同学有问过怎么能拿到阿里算法类校招的offer,刚好看到这篇文章分享给大家,详情可以看原文链接,原文链接中有视频讲解. 师兄师姐的建议: 之前初学算法的时候上过的公开课和看过的书 1. Cours ...

  4. android 自定义空间 组合控件中 TextView 不支持drawableLeft属性

    android 自定义空间 组合控件中 TextView 不支持drawableLeft属性.会报错Caused by: android.view.InflateException: Binary X ...

  5. RedHat/CentOS 大文件拆分及合并与md5验证

    [root@tdh55 mnt]# cd /opt/[root@tdh55 opt]# ll -h-rw-r--r--. 1 root root 7.5G May 12 11:19 TDH-Image ...

  6. 「JavaSE 重新出发」05.03.03 使用反射编写泛型数组代码

    Employee[] a = new Employee[100]; // ... // array is full a = Arrays.copyOf(a, 2 * a.length); 如何编写这样 ...

  7. Vs2010无法打开文件“Kernel32.lib”、无法打开“libcpmt.lib”"msvcprt.lib"

    1.对于无法打开"Kernel"问题,即使复制lib文件到目录,仍然会出现最后的错误; 原因:WindowsSdk 安装失败! 方法:重装 microsoft SDK6.0 ,再在 ...

  8. C语言break/continue/exit/return的功能区别

    break是跳出整个循环而执行循环体之外的下一条语句: continue只是跳出本次循环继续判断下一次循环条件是否满足. exit() 结束当前进程/当前程式/,在整个程式中,只要调用 exit ,就 ...

  9. Mysql 5.7 for windows 免安装版(解压版)安装和配置

    网上写的不近详细,这里重新整理下. 准备: 1.windows操作系统 2.mysql 的解压版压缩文件 第一步: 解压mysql的压缩包到你的安装目录,因为是虚拟机,这里我就安装在C盘下:C:\my ...

  10. Aeroplane chess HDU - 4405_数学期望_逆推

    Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...