关于spring和extjs对接的过程简述
<?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对接的过程简述的更多相关文章
- 工厂模式模拟Spring的bean加载过程
一.前言 在日常的开发过程,经常使用或碰到的设计模式有代理.工厂.单例.反射模式等等.下面就对工厂模式模拟spring的bean加载过程进行解析,如果对工厂模式不熟悉的,具体可以先去学习一下工厂 ...
- Spring之IOC容器初始化过程
Ioc容器的初始化是由refresh()方法来启动的,这个方法标志着Ioc容器的正式启动. 具体来说这个启动过程包括三个基本过程: 1.BeanDifinition的Resource定位 2.Bean ...
- 升级到 ExtJS 5的过程记录
升级到 ExtJS 5的过程记录 最近为公司的一个项目创建了一个 ExtJS 5 的分支,顺便记录一下升级到 ExtJS 5 所遇到的问题以及填掉的坑.由于 Sencha Cmd 的 sencha ...
- spring internalTransactionAdvisor 事务 advisor 初始化过程
spring internalTransactionAdvisor 事务 advisor 初始化过程:
- Spring容器的创建刷新过程
Spring容器的创建刷新过程 以AnnotionConfigApplicationContext为例,在new一个AnnotionConfigApplicationContext的时候,其构造函数内 ...
- Spring IOC容器创建bean过程浅析
1. 背景 Spring框架本身非常庞大,源码阅读可以从Spring IOC容器的实现开始一点点了解.然而即便是IOC容器,代码仍然是非常多,短时间内全部精读完并不现实 本文分析比较浅,而完整的IOC ...
- Spring Security 解析(二) —— 认证过程
Spring Security 解析(二) -- 认证过程 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...
- Spring Security 解析(一) —— 授权过程
Spring Security 解析(一) -- 授权过程 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...
- Spring Bean 的加载过程
Spring Bean 的加载过程 一个是populateBean,一个是initializeBean,这两个方法完成了bean的赋值与初始化. 这里有一个BeanDefinitionValueRes ...
随机推荐
- CI中的分页
根据MVC的思想,分页是需要传数据到模型中,把页码传过去,在模型中根据页码分配: 更多分页类函数可以通过CI手册的分页类查看: $this -> load ->library('pagin ...
- 杭电 1040 As Easy As A+B 【排序】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1040 解题思路:数据不大,可以直接用冒泡排序 #include<stdio.h> int ...
- 【技术累积】【点】【java】【4】日志级别
闲聊 水文也是文,写总比不写好. 日志级别 虽然对其他语言的日志系统也不甚了解,但还是感觉Java的日志有些麻烦,当然也可以说是发展已久,多有变化,多有完善吧. 从日志级别来说,有从高到低的八个级别: ...
- 遍历及过滤 first(), last() 和 eq() filter() 和 not()
三个最基本的过滤方法是:first(), last() 和 eq(),它们允许您基于其在一组元素中的位置来选择一个特定的元素.其他过滤方法,比如 filter() 和 not() 允许您选取匹配或不匹 ...
- httpclient模拟浏览器
package com.java.httpclient; import java.io.IOException; import org.apache.http.HttpEntity; import o ...
- input标签处理多文件上传
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- [luogu3627 APIO2009] 抢掠计划 (tarjan缩点+spfa最长路)
传送门 Description Input 第一行包含两个整数 N.M.N 表示路口的个数,M 表示道路条数.接下来 M 行,每行两个整数,这两个整数都在 1 到 N 之间,第 i+1 行的两个整数表 ...
- 2019-03-28 SQL Server char/nchar/nvarchar
带n 的是用于处理unicode 字符,即处理中英文的字符 一般来说,如果含有中文字符,用nchar/nvarchar,如果纯英文和数字,用char/varchar char 定长 char(10), ...
- [Design]Ppt处理大段文字
可以用标签类的东西 时间轴
- [SharePoint2010开发入门经典]一、SPS2010介绍
本章概要: 1.熟悉SPS基本特性 2.理解SPS基础架构 3.开发SPS工具