- 浏览: 390930 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (196)
- window编程 (18)
- FLEX (37)
- 数据库 (5)
- Java---Struts2 (8)
- Window相关知识 (4)
- 网站建设相关知识 (2)
- java基础知识 (6)
- C# (8)
- 虚拟化 (3)
- 服务器--sound server (1)
- 网络协议 (5)
- Linux (21)
- linux-命令 (3)
- Windows-2008R2 (1)
- VBScript,异常处理 (1)
- windows域 (1)
- 弦歌不辍 (1)
- 语言---c++ (16)
- MFS (1)
- grub (1)
- 技术介绍 (3)
- 百度之星 (5)
- Web服务 (1)
- 存储管理 (2)
- NoSQL (3)
- plymouth (1)
- 工具 (1)
- 云计算 (1)
- 嵌入式 (1)
- usbip (1)
最新评论
-
canghailan:
C++中能直接操作的最大位数64,每64位统计,最后相加,暂时 ...
判断一段内存是否全部为0 -
yiranwuqing:
canghailan 写道Hamming weight 算法应 ...
判断一段内存是否全部为0 -
canghailan:
Hamming weight 算法应该效率更高
判断一段内存是否全部为0 -
zoufangyingzi:
楼主都用了哪些jar包,压缩包中没有lib包///
Rest实例演示 -
zpz112358:
具体是什么意思啊?
flex blazed 配置多个remoting-config
采用filter 监控 MessageBrokerServlet 把context 放入 ThreadLocal 中
然后你就可以从 java 程序的任何 方法中 利用 ThreadLocal 得到 当前的session
这个时候结合aop 我采用spring 的aop 在需要 session 验证的方法前 调用一个 Interceptor 来验证 session 过期或者其他权限等
具体代码:
web.xml 中
[复制到剪贴板]
CODE:
<filter>
<filter-name>AMFContextFilter</filter-name>
<filter-class>flex.context.AMFContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AMFContextFilter</filter-name>
<servlet-name>MessageBrokerServlet</servlet-name>
</filter-mapping>
AMFContextFilter文件
[复制到剪贴板]
CODE:
package flex.context;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AMFContextFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException {
AMFContext.setCurrentContext((HttpServletRequest) request,
(HttpServletResponse) response);
chain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
public void destroy() {
// TODO Auto-generated method stub
}
}
AMFContext文件
[复制到剪贴板]
CODE:
package flex.context;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class AMFContext {
/**
* ThreadLocal object for storing object in current thread.
*/
private static ThreadLocal tl = new ThreadLocal();
/**
* Set current context
*
* @param request
* The HttpRequest object
* @param response
* The HttpResponses object
*/
@SuppressWarnings(&quot;unchecked&quot;)
static public void setCurrentContext(HttpServletRequest request,
HttpServletResponse response) {
AMFContext c = getCurrentContext();
if (c == null) {
c = new AMFContext(request, response);
tl.set(c);
} else {
c.setRequest(request);
c.setResponse(response);
}
}
/**
* Get current context value
*
* @return The current context
*/
static public AMFContext getCurrentContext() {
return (AMFContext) tl.get();
}
// ----------------------------------------------------------
//
// Class members
//
// ----------------------------------------------------------
/**
* The http request object. The lifecycle of the request object is defined
* as the request scope. It may be reused in another incoming connection, so
* dont use it in another thread.
*/
private HttpServletRequest request;
/**
* The http response object. The lifecycle of the response object is defined
* as the request scope. Dont use it in another thread. Also dont write
* output to the response when it is used in the context, but you may get or
* set some response header when it is safe.
*/
private HttpServletResponse response;
/**
* The constructor is private, to get an instance of the AMFContext, please
* use getCurrentContext() method.
*
* @param request
* @param response
*/
private AMFContext(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
}
/**
* Get request object
*
* @return Http request object
*/
public HttpServletRequest getRequest() {
return request;
}
/**
* Set request object
*
* @param Http
* request object
*/
public void setRequest(HttpServletRequest request) {
this.request = request;
}
/**
* Get response object
*
* @return Http response object
*/
public HttpServletResponse getResponse() {
return response;
}
/**
* Set response object
*
* @param response
* Http response object
*/
public void setResponse(HttpServletResponse response) {
this.response = response;
}
/**
* Get the servlet context
*
* @return
*/
public ServletContext getServletContext() {
HttpSession session = this.getSession();
return session.getServletContext();
}
/**
* Get the current running session
*
* @return
*/
public HttpSession getSession() {
return request.getSession();
}
/**
* Get an object stored in the session.
*
* @param attr
* Attribute Name
* @return The value stored under the attribute name.
*/
public Object getSessionAttribute(String attr) {
HttpSession session = this.getSession();
return session.getAttribute(attr);
}
/**
* Store an object in the session.
*
* @param attr
* Attribute Name
* @param value
* The value.
*/
public void setSessionAttribute(String attr, Object value) {
HttpSession session = this.getSession();
session.setAttribute(attr, value);
}
/**
* Get an object stored in the servlet context.
*
* @param attr
* Attribute Name
* @return The value stored under the attribute name.
*/
public Object getContextAttribute(String attr) {
ServletContext sc = this.getServletContext();
return sc.getAttribute(attr);
}
/**
* Store an object in the servlet context.
*
* @param attr
* Attribute Name
* @param value
* The value.
*/
public void setContextAttribute(String attr, Object value) {
ServletContext sc = this.getServletContext();
sc.setAttribute(attr, value);
}
/**
* Get an object stored in the current request.
*
* @param attr
* Attribute Name
* @return The value stored under the attribute name.
*/
public Object getRequestAttribute(String attr) {
return request.getAttribute(attr);
}
/**
* Store an object in the current request.
*
* @param attr
* Attribute Name
* @param value
* The value.
*/
public void setRequestAttribute(String attr, Object value) {
request.setAttribute(attr, value);
}
}
MethodInterceptor 文件
[复制到剪贴板]
CODE:
package com.sunwayworld.flex;
import javax.servlet.http.HttpServletRequest;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import com.sunwayworld.common.utils.SessionUtils;
import flex.context.AMFContext;
public class FlexSessionInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
AMFContext context = AMFContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
if (!SessionUtils.isLogin(request)) {
throw new RuntimeException(&quot;请您重新登陆!&quot;);
}
Object obj = invocation.proceed();
return obj;
}
}
然后 在spring 配置 成调用所有的java 方法前都执行这个 MethodInterceptor 即可
然后你就可以从 java 程序的任何 方法中 利用 ThreadLocal 得到 当前的session
这个时候结合aop 我采用spring 的aop 在需要 session 验证的方法前 调用一个 Interceptor 来验证 session 过期或者其他权限等
具体代码:
web.xml 中
[复制到剪贴板]
CODE:
<filter>
<filter-name>AMFContextFilter</filter-name>
<filter-class>flex.context.AMFContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AMFContextFilter</filter-name>
<servlet-name>MessageBrokerServlet</servlet-name>
</filter-mapping>
AMFContextFilter文件
[复制到剪贴板]
CODE:
package flex.context;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AMFContextFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException {
AMFContext.setCurrentContext((HttpServletRequest) request,
(HttpServletResponse) response);
chain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
public void destroy() {
// TODO Auto-generated method stub
}
}
AMFContext文件
[复制到剪贴板]
CODE:
package flex.context;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class AMFContext {
/**
* ThreadLocal object for storing object in current thread.
*/
private static ThreadLocal tl = new ThreadLocal();
/**
* Set current context
*
* @param request
* The HttpRequest object
* @param response
* The HttpResponses object
*/
@SuppressWarnings(&quot;unchecked&quot;)
static public void setCurrentContext(HttpServletRequest request,
HttpServletResponse response) {
AMFContext c = getCurrentContext();
if (c == null) {
c = new AMFContext(request, response);
tl.set(c);
} else {
c.setRequest(request);
c.setResponse(response);
}
}
/**
* Get current context value
*
* @return The current context
*/
static public AMFContext getCurrentContext() {
return (AMFContext) tl.get();
}
// ----------------------------------------------------------
//
// Class members
//
// ----------------------------------------------------------
/**
* The http request object. The lifecycle of the request object is defined
* as the request scope. It may be reused in another incoming connection, so
* dont use it in another thread.
*/
private HttpServletRequest request;
/**
* The http response object. The lifecycle of the response object is defined
* as the request scope. Dont use it in another thread. Also dont write
* output to the response when it is used in the context, but you may get or
* set some response header when it is safe.
*/
private HttpServletResponse response;
/**
* The constructor is private, to get an instance of the AMFContext, please
* use getCurrentContext() method.
*
* @param request
* @param response
*/
private AMFContext(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
}
/**
* Get request object
*
* @return Http request object
*/
public HttpServletRequest getRequest() {
return request;
}
/**
* Set request object
*
* @param Http
* request object
*/
public void setRequest(HttpServletRequest request) {
this.request = request;
}
/**
* Get response object
*
* @return Http response object
*/
public HttpServletResponse getResponse() {
return response;
}
/**
* Set response object
*
* @param response
* Http response object
*/
public void setResponse(HttpServletResponse response) {
this.response = response;
}
/**
* Get the servlet context
*
* @return
*/
public ServletContext getServletContext() {
HttpSession session = this.getSession();
return session.getServletContext();
}
/**
* Get the current running session
*
* @return
*/
public HttpSession getSession() {
return request.getSession();
}
/**
* Get an object stored in the session.
*
* @param attr
* Attribute Name
* @return The value stored under the attribute name.
*/
public Object getSessionAttribute(String attr) {
HttpSession session = this.getSession();
return session.getAttribute(attr);
}
/**
* Store an object in the session.
*
* @param attr
* Attribute Name
* @param value
* The value.
*/
public void setSessionAttribute(String attr, Object value) {
HttpSession session = this.getSession();
session.setAttribute(attr, value);
}
/**
* Get an object stored in the servlet context.
*
* @param attr
* Attribute Name
* @return The value stored under the attribute name.
*/
public Object getContextAttribute(String attr) {
ServletContext sc = this.getServletContext();
return sc.getAttribute(attr);
}
/**
* Store an object in the servlet context.
*
* @param attr
* Attribute Name
* @param value
* The value.
*/
public void setContextAttribute(String attr, Object value) {
ServletContext sc = this.getServletContext();
sc.setAttribute(attr, value);
}
/**
* Get an object stored in the current request.
*
* @param attr
* Attribute Name
* @return The value stored under the attribute name.
*/
public Object getRequestAttribute(String attr) {
return request.getAttribute(attr);
}
/**
* Store an object in the current request.
*
* @param attr
* Attribute Name
* @param value
* The value.
*/
public void setRequestAttribute(String attr, Object value) {
request.setAttribute(attr, value);
}
}
MethodInterceptor 文件
[复制到剪贴板]
CODE:
package com.sunwayworld.flex;
import javax.servlet.http.HttpServletRequest;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import com.sunwayworld.common.utils.SessionUtils;
import flex.context.AMFContext;
public class FlexSessionInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
AMFContext context = AMFContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
if (!SessionUtils.isLogin(request)) {
throw new RuntimeException(&quot;请您重新登陆!&quot;);
}
Object obj = invocation.proceed();
return obj;
}
}
然后 在spring 配置 成调用所有的java 方法前都执行这个 MethodInterceptor 即可
发表评论
-
flex使用amchart的破解水印方法
2010-12-23 10:18 2824需要继承AmChart的类,将宽、高、透明度设成0,例如: ... -
FLEX习作:图片轮播(18种过渡效果随机应用)
2010-08-29 00:51 2356主文件imgshow.mxml: 引用 <?xml v ... -
AS3及Flex的百条常用知识
2010-08-27 17:38 1559【自动大小调整和对齐】 TextField.autoSize ... -
Flex:在PANEL的title上加一个button
2010-08-26 16:30 1396在panel的titleBar上添加按钮,首先 overrid ... -
flex blazed 配置多个remoting-config
2010-08-22 17:37 2232我把配置贴出来,大家如果有类似需求可以参考下: remoti ... -
flex chart网站
2010-08-22 12:25 1863http://examples.adobe.com/flex2 ... -
FLEX:TypeError: Error #1034解决
2010-07-25 15:17 1687LEX:TypeError: Error #1034: 強制轉 ... -
页面跳转问题
2010-07-25 15:15 985其实对于这个题目是不恰当的,因为flex中是没有页面这个概念的 ... -
AIR的绿化
2010-07-25 14:35 767http://hi.baidu.com/fsnhf/blog/ ... -
flex中扩展combobox功能
2010-07-23 22:54 1342近段时间在忙flex的东西,边学习边使用。里边有个ComboB ... -
Flex调用Webservice时可能产生的所有错误,监控哪些错误
2010-07-22 22:22 2336判断web服务是否没有方法,是否路径错误,是否编码错误,是否解 ... -
flex Webservice 有哪些事件可监控
2010-07-22 21:25 1140private var webserviceURL:WebSe ... -
Flex跨域调用Webservice问题
2010-07-22 18:05 1961最近在用Flex做一个项目,在本机调试一切正常,传到服务器上之 ... -
Flex 字体使用
2010-07-20 22:36 1308Flex 支持的True Type和Open Type类型的字 ... -
个人总结flex各种用法
2010-07-20 22:29 1697多篇日志总结的,非原创,但为了更多人看这篇不错的日志,设置为原 ... -
Flex 平铺背景图片
2010-07-20 21:54 2146package { import flash.geom.Rec ... -
使用flex的session
2010-07-20 21:48 9901.写 session mxml 文件 加 <mx ... -
Flex DataGrid 内联 itemRenderer
2010-07-20 14:51 2504dp.itemUpdated(event.data," ... -
LocalConnection实现swf与swf之间通信
2010-07-19 22:40 3193LocalConnection可以实现swf与swf之间的通信 ... -
对于FLex中有些服务器不可达解决
2010-07-18 12:23 857在Flash安全模型限制作出插座连接到任何服务器不明确允许这样 ...
相关推荐
控制器会调用相应的服务方法,该方法利用Hibernate的Session接口创建新的实体对象并保存到数据库。 2. **删除(Delete)**:用户选择要删除的条目,Flex发送包含ID的请求到Spring的Delete接口。控制器根据ID找到...
1. `<listener>`标签定义了一个监听器`flex.messaging.HttpFlexSession`,用于支持Flex通信的session。 2. `<servlet>`标签定义了名为`MessageBrokerServlet`的servlet,它是Blazeds的核心,处理与Flex客户端的通信...
例如,UserService可能会有一个saveUser(User user)方法,通过Session的save()或saveOrUpdate()方法将用户信息持久化到数据库。 Flex客户端与服务端的交互主要基于AMF(Action Message Format),这是一种高效的...
- 它包括一系列组件,如MessageBrokerServlet、HTTP Flex Session、Remoting服务等,用于实现远程方法调用、消息代理和数据推送。 4. **集成过程**: - 创建一个J2EE Web工程,如`Sample`,作为后端服务的基础。 ...
当涉及到与Hibernate的集成时,Spring提供了对Hibernate的全面支持,可以管理SessionFactory和Session。在配置文件中,我们可以定义数据访问层的bean,比如`SessionFactory`,并利用Spring的事务管理功能来处理...
10. **部署描述符** (`web.xml`):这是Java Web应用程序的核心配置文件,定义了过滤器、监听器、Servlet等元素,控制着应用的启动和运行行为。 通过以上配置,开发者可以创建一个强大的、灵活的Web应用程序,具有...
4. 使用Hibernate的Session接口进行数据库操作,如Session.save()、Session.load()、Session.update()和Session.delete()。 5. 结果封装为XML或JSON格式,通过Struts返回给Flex。 6. Flex接收到响应后更新UI。 深入...
通过定义目的地和指定方法访问权限,我们可以精细控制Flex应用程序与后端Java服务的交互,确保安全性和性能。在实际开发中,根据项目的具体需求,灵活调整`remote-config.xml`的配置,可以实现各种复杂的远程服务...
Spring MVC+BlazeDS+Flex框架实践:HelloWorld篇是一个典型的多层架构示例,它结合了Spring MVC作为后端控制器、BlazeDS作为数据通信中间件,以及Flex作为前端展示技术。本实践旨在帮助开发者了解如何将这些技术集成...
5. **Model-View-Controller(MVC)**:Spring的MVC模式使得前端Flex和后端业务逻辑之间有清晰的分隔,Flex负责视图和用户交互,Spring负责控制流程和业务逻辑。 6. **数据绑定**:Flex与Hibernate整合后,可以利用...
在Flex客户端,我们可以创建RemoteObject,指定其目标为Spring的bean,这样就可以调用后端的方法并处理返回的数据。 安全方面,Spring Security或Acegi(Spring的早期安全模块)可以用来保护应用的资源,提供认证和...
6. DAO层:创建`UserDAO.java`,包含具体的数据访问操作,如`findUserByUsernameAndPassword`方法。 五、Flex客户端开发 1. 使用FlashBuilder创建Flex项目,与后端的Struts2 Action进行通信,通常通过AMF(Action ...
Struts2允许开发者将业务逻辑与视图和控制层分离,提供了一套灵活的拦截器和插件机制。在这个示例中,Flex4发送的HTTP请求会被Struts2拦截并处理,执行相应的登录验证逻辑,如检查用户名和密码是否匹配。 **...
- 支持从Session中获取当前用户和访问级别信息,便于权限控制。 - 提供了方便的方法将请求参数映射到对象属性,简化了数据绑定过程。 **3.2 BaseBusiness的角色与功能** - **设计原则:** - 业务逻辑集中管理,...
- 在Cairngorm基础上进一步改进,使用FrontController模式可以更好地控制请求处理流程,提高系统的灵活性和可维护性。 5. **轮回转世—Mate样例** - Mate框架提供了一种更加轻量级的选择,适用于那些不需要...
6. 控制器层:Spring MVC的Controller类,负责处理Flex发送的HTTP请求,调用服务层方法,并返回响应数据。 7. 测试:可能包含单元测试和集成测试,验证各层的功能和协作。 这个示例项目可以帮助初学者理解如何在...
4. **建立数据访问层**:使用Hibernate的SessionFactory和Session接口,通过注解或XML映射文件来实现对象与数据库表之间的映射。 5. **Spring与Hibernate整合**:将Hibernate的SessionFactory注入到Spring中,通过...
总而言之,Flex 3界面布局教程第二篇深入介绍了Form和Grid这两种布局容器的使用方法和实现示例。通过对这两种布局方式的学习和实践,开发者可以更好地掌握Flex 3在界面布局方面的高级应用。Flex 3布局容器的灵活性和...
`flex-direction`定义主轴方向,`justify-content`调整沿主轴的对齐方式,`align-items`控制跨轴对齐,`align-self`允许单独调整子元素的跨轴对齐,以及`flex-grow`, `flex-shrink`和`flex-basis`用于控制伸缩比例和...