ServletActionContext 源码
/*
* $Id: ServletActionContext.java 651946 2008-04-27 13:41:38Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ package org.apache.struts2; import java.util.Map; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext; import org.apache.struts2.dispatcher.mapper.ActionMapping; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack; /**
* Web-specific context information for actions. This class subclasses <tt>ActionContext</tt> which
* provides access to things like the action name, value stack, etc. This class adds access to
* web objects like servlet parameters, request attributes and things like the HTTP session.
*/
public class ServletActionContext extends ActionContext implements StrutsStatics { private static final long serialVersionUID = -666854718275106687L; public static final String STRUTS_VALUESTACK_KEY = "struts.valueStack";
public static final String ACTION_MAPPING = "struts.actionMapping"; @SuppressWarnings("unused")
private ServletActionContext(Map context) {
super(context);
} /**
* Gets the current action context
*
* @param req The request
* @return The current action context
*/
public static ActionContext getActionContext(HttpServletRequest req) {
ValueStack vs = getValueStack(req);
if (vs != null) {
return new ActionContext(vs.getContext());
} else {
return null;
}
} /**
* Gets the current value stack for this request
*
* @param req The request
* @return The value stack
*/
public static ValueStack getValueStack(HttpServletRequest req) {
return (ValueStack) req.getAttribute(STRUTS_VALUESTACK_KEY);
} /**
* Gets the action mapping for this context
*
* @return The action mapping
*/
public static ActionMapping getActionMapping() {
return (ActionMapping) ActionContext.getContext().get(ACTION_MAPPING);
} /**
* Returns the HTTP page context.
*
* @return the HTTP page context.
*/
public static PageContext getPageContext() {
return (PageContext) ActionContext.getContext().get(PAGE_CONTEXT);
} /**
* Sets the HTTP servlet request object.
*
* @param request the HTTP servlet request object.
*/
public static void setRequest(HttpServletRequest request) {
ActionContext.getContext().put(HTTP_REQUEST, request);
} /**
* Gets the HTTP servlet request object.
*
* @return the HTTP servlet request object.
*/
public static HttpServletRequest getRequest() {
return (HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
} /**
* Sets the HTTP servlet response object.
*
* @param response the HTTP servlet response object.
*/
public static void setResponse(HttpServletResponse response) {
ActionContext.getContext().put(HTTP_RESPONSE, response);
} /**
* Gets the HTTP servlet response object.
*
* @return the HTTP servlet response object.
*/
public static HttpServletResponse getResponse() {
return (HttpServletResponse) ActionContext.getContext().get(HTTP_RESPONSE);
} /**
* Gets the servlet context.
*
* @return the servlet context.
*/
public static ServletContext getServletContext() {
return (ServletContext) ActionContext.getContext().get(SERVLET_CONTEXT);
} /**
* Sets the current servlet context object
*
* @param servletContext The servlet context to use
*/
public static void setServletContext(ServletContext servletContext) {
ActionContext.getContext().put(SERVLET_CONTEXT, servletContext);
}
}
ServletActionContext 源码的更多相关文章
- Struts2 源码分析——Result类实例
本章简言 上一章笔者讲到关于DefaultActionInvocation类执行action的相关知识.我们清楚的知道在执行action类实例之后会相关处理返回的结果.而这章笔者将对处理结果相关的内容 ...
- Struts2 源码分析——Action代理类的工作
章节简言 上一章笔者讲到关于如何加载配置文件里面的package元素节点信息.相信读者到这里心里面对struts2在启动的时候加载相关的信息有了一定的了解和认识.而本章将讲到关于struts2启动成功 ...
- Struts2 源码分析——调结者(Dispatcher)之执行action
章节简言 上一章笔者写关于Dispatcher类如何处理接受来的request请求.当然读者们也知道他并非正真的执行action操作.他只是在执行action操作之前的准备工作.那么谁才是正真的执行a ...
- struts请求源码的跟踪
最近工作任务不是很紧,时间也不能白白浪费,以前常用的struts2框架源码没去了解过,所以就跟踪一下struts2的整个执行过程.由于本人也是抱着学习的态度来阅读掩码,若文章在表述和代码方面如有不妥之 ...
- Struts2运行流程-源码剖析
本文为原创,如需转载,请标明出处:http://www.cnblogs.com/gudu1/p/7726172.html 首先说一下查看这些框架源码的感受,每一次深入探究 Spring.Struts ...
- Struts2源码解析2
看了前面一节对Struts2各个模块运行有了大概了解,也对调用的函数有了一定的了解,本节希望打断点跑一个Struts2例子! 还是放在struts2结构图: 一:项目启动后解析web.xml文件,会解 ...
- 我的SSH框架实例(附源码)
整理一下从前写的SSH框架的例子,供新人学习,使用到了注解的方式. 源码和数据库文件在百度网盘:http://pan.baidu.com/s/1hsH3Hh6 提取码:br27 对新同学的建议:最好的 ...
- SSH框架总结(环境搭建+框架分析+实例源码下载)
一.SSH框架简介 SSH是struts+spring+hibernate集成的web应用程序开源框架. Struts:用来控制的,核心控制器是Controller. Spring:对Struts和H ...
- 源码分析——Action代理类的工作
Action代理类的新建 通过<Struts2 源码分析——调结者(Dispatcher)之执行action>章节我们知道执行action请求,最后会落到Dispatcher类的serv ...
随机推荐
- Repeater控件里面取不到CheckBox的值
然后在后台需要取到,选中了那些 然后在后台怎么取也取不到,当时就纳闷了,然后开始怀疑自己的代码是不是错了,经过仔细一看,我的妈呀,加载事件了差一句话......整个人都不好了 加载事件差这句话不行,补 ...
- maven手动导入jar包到本地仓库
一.cmd进入maven的bin目录下(我的目录是E:\cloud_cms\apache-maven-3.5.4\bin) cd E:\cloud_cms\apache-maven-3.5.4\bin ...
- 统计学基于SPSS贾俊平 授课笔记 发布作业 spss19cn 软件下载地址及破解包spss19_10039 下载地址
spss19cn软件下载地址及破解包spss19_10039 软件包下载地址一 http://www.33lc.com/soft/41991.html 软件包下载地址二 http://dl.pconl ...
- c++程序设计第三版例题1.2 求两数的和
#include <iostream>using namespace std; int main(){ //求两数之和 int a,b,sum; a=11; b=22; sum=a+b; ...
- PHP 对象基础知识
最近开始重新学习对象知识,其实也算是初步深入学习对象和设计模式,希望自己会坚持下去,保持更新 初识PHP对象 还记得,刚开始学习 PHP 的时候,学到到方法和对象时有一个很大的疑问,对象与方法相比较那 ...
- 19.VUE学习之- v-for与computed结合功能 筛选实例讲解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 循环(while、for)
写重复的代码是程序员最不耻的行为,那么如何做到不用写重复代码又能让程序重复一段代码多次呢,循环语句就派上用场拉…… 一.while 循环 # while 语法结构 while 条件: 执行代码.... ...
- 2、python中的数字
第二篇开始谈谈python中的数据. 一.前言 python中的数字包含了整数.浮点数.复数三种.在python的早期版本,或许可以看到正数被分为长整数与短整数,后来被取消了,因此这里不作讨论.通常我 ...
- Win7系统桌面便签怎么添加?
参考:http://jingyan.baidu.com/article/ab69b270c207432ca7189f99.html Win7系统桌面便签怎么添加?有时候工作.学习忙起来就会忘记要办的事 ...
- spark 的createDstream和createDirectStream区别
spark读取kafka数据流提供了两种方式createDstream和createDirectStream. 两者区别如下: 1.KafkaUtils.createDstream 构造函数为Kafk ...