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 ...
随机推荐
- window7防火墙无法更改某些设置,错误代码0×80070422
原因:这是由于管理工具的服务中的windows防火墙被禁用了. 解决方案:在window7中点击控制面板,然后点击管理工具,在点服务,然后找到windows firewall 然后将其改为自动就就可以 ...
- appuim操作webview控件
1.操作webview控件,在uiautomator中如下图,能定位的只有最外层的内容.就一个webview控件,查找不到里面内容 1.使用driver.getContext(),获取是否是webvi ...
- hdu-2680 Choose the best route---dijkstra+反向存图或者建立超级源点
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目大意: 给你一个有向图,一个起点集合,一个终点,求最短路 解题思路: 1.自己多加一个超级 ...
- ZJOI2004 午餐
题目传送门 嗯--我承认我看了题解,不过好歹有了点自己的思路,大约蒙出来了\(30\%\)(个人感觉)-- 学会\(DP\),任重而道远啊! Step1.贪心排序 先将每个人按吃饭的快慢排序,然后再进 ...
- Python小脚本程序
本文旨在搜集最简单最原子性的代码块,简单清晰容易阅读,然后由用户自己组合.Python代码排版请自行修改. 这里是索引目录: 1. 下载网站文件 2. 下载网站多个文件 1. 下载网站文件 impor ...
- 分享12款最佳的Bootstrap设计工具
设计师总会渴望有一些新奇有趣的设计工具来提高工作效率,而Bootstrap就是您的不二选择.2013年Bootstrap得到了广泛普及, 它是开发者较为常用的框架之一,本文我们将分享12款最佳的Boo ...
- python查看安装包
D:\Python27\Scripts>pip listbackports.ssl-match-hostname (3.4.0.2)basicauth (0.2)certifi (14.5.14 ...
- 适配iOS10和Xcode8
1.权限设置 iOS10,访问系统权限需要在info.plist中注册,否则直接crash! 注意,Value值不可为空,否则会被Appstore拒掉! 2.Notification,学习资料 喵神总 ...
- react的ant design的UI组件库
PC官网:https://ant.design/ 移动端网址:https://mobile.ant.design/docs/react/introduce-cn antd-mobile :是 Ant ...
- Atlas 配置高可用
keepalived安装 #下载keepalived ./configure --prefix=/usr/local Make && make install Atlas主安装keep ...