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 ...
随机推荐
- HDU1664 BFS + 数论 + 剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1664 , 一道比较蛋疼的搜索题. 这道题有很多坑点,一点处理不好就要TLE. 题意很简单,就是找到一个 ...
- UML复习1-2章
第一章 1.请对SDLC的六个阶段排序 1> 可行性分析 2> 设计 3> 测试 4> 维护 5> 需求分析与说明 6> 编码 A. 1 5 2 6 3 4 B. ...
- Linux内核参数min_free_kbytes
1. min_free_kbytes 先看官方解释: This is used to force the Linux VM to keep a minimum number of kilobytes ...
- 阿里云服务器下安装LAMP环境(CentOS Linux 6.3) 安装与配置 Apache 服务
想让我们的阿里云服务器成为一台 Web 服务器,我们需要安装一个 Web 服务器软件,比如 Apache ,或者 Nginx 等等.下面我们就一起来安装一个 Apache 服务. 我们可以使用 yum ...
- 表格和网页ico图标
表格: 表格格式: <table> <tr> 表格的行 <th >表头</th> <th>表头 </th> </tr> ...
- 国产中标麒麟Linux部署dotnet core 环境并运行项目 (一) 安装dotnet core
背景 根据我之前写的文章 将 Net 项目升级 Core项目经验:(一)迁移Net项目为Net Core\Standard项目,我们将公司内部最核心的ORM框架迁移到net core 上面,并在win ...
- SpringMVC解决前台传入的数组或集合类型数据
1前台处理如下: $.ajax({ url:"saveMapInfo", type:"POST", dataType:"json", con ...
- 转载:java分布式服务框架Dubbo的介绍与使用
1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需 ...
- flask-bootstrap
pip install bootstarp 使用bower安装bootstrap的命令是: bash$ bower install bootstrap不过问题出在如何安装bower上. 官方网站上这样 ...
- Python小项目之五子棋
1.项目简介 在刚刚学习完python套接字的时候做的一个五子棋小游戏,可以在局域网内双人对战,也可以和电脑对战 2.实现思路 局域网对战 对于局域网功能来说,首先建立连接(tcp),然后每次下棋时将 ...