struts2中在Action中如何获取servlet的api?
1.通过ActionContext类(拿到的不是真正的servlet api,而是一个map)
ActionContext context = ActionContext.getContext();
context.getSession();
context.getApplication();
2.通过ServletActionContext类(拿到的是真正的servlet api)
ServletActionContext.getRequest();
ServletActionContext.getResponse();
ServletActionContext.getPageContext();
3.通过注入方式获取(拿到的是真正的servlet api)
* ServletContextAware、ServletRequestAware、ServletResponseAware接口
(1) 实现对应的接口:implements ServletRequestAware
(2) 声明私有属性例如 private HttpServletRequest request;
(3) 复写接口方法setsetServletRequest
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
struts2中在Action中如何获取servlet的api?的更多相关文章
- Struts2获取Servlet的api的两种方式,解决ParameterAware过时的问题
servlet API通过ActionContext进行获取 Struts2对HttpServletRequest,HttpSession和ServletContext进行了封装,构造了3个Map对象 ...
- struts2:在Action中使用Servlet的API,设置、读取各种内置对象的属性
有两种方式可以实现在Action中使用Servlet的API.一种是使用org.apache.struts2.ServletActionContext类,另一种是使用com.opensymphony. ...
- struts2中把action中的值传递到jsp页面的例子
例子: RegistAction的代码: package com.wss.action; import javax.servlet.http.HttpServletRequest; import or ...
- struts2学习笔记(四)——访问Servlet的API&结果跳转&数据封装
一.Struts2访问Servlet的API 前面已经对Struts2的流程执行完成了,但是如果表单中有参数如何进行接收?又或者我们需要向页面保存一些数据,又要如何完成呢?我们可以通过学习Struts ...
- (4)获取servlet常用api
*五)与ServletAPI解耦 方式1 AddAction public String execute() throws Exception, IOException{ //获取请求对象reques ...
- 获取Servlet原生API
1.请求 <a href="param/test1">Servlet原生API</a> 2.处理方法 @RequestMapping("/para ...
- struts2使用注解--ACTION中的应用
1.在类中指定包:@ParentPackage("system").其中system是在struts.xml中定义的包名.2.配置文件--->注解2.1配置文件方式(返回js ...
- Struts2框架中使用Servlet的API示例
1. 在Action类中也可以获取到Servlet一些常用的API * 需求:提供JSP的表单页面的数据,在Action中使用Servlet的API接收到,然后保存到三个域对象中,最后再显示到JSP的 ...
- 在Struts2框架中使用Servlet的API
1. 在Action类中也可以获取到Servlet一些常用的API * 需求:提供JSP的表单页面的数据,在Action中使用Servlet的API接收到,然后保存到三个域对象中,最后再显示到JSP的 ...
随机推荐
- LA 3026 Period
这只是蓝书上的一道KMP水题...然后对于最长前缀的循环证明我就不说了... #include<iostream> #include<cstring> #include< ...
- unity3d Billboard
CameraFacingBillboard CameraFacingBillboard From Unify Community Wiki Jump to: navigation, searc ...
- 程设刷题 | 编译C++文件出现to_string is not a member of std 或者 to_string was not declared in this scope的解决方法
写在前面 原文链接:Enabling string conversion functions in MinGW C++在将整型.浮点型.长整型等数据类型转换为字符串时,可使用<string> ...
- 说一说ST表 讲一讲水题
ST表 一.算法介绍 如何快速求解RMQ问题呢?暴力复杂度O(n),线段树复杂度O(n)~O(logn),要是数据规模达到10^7或者更高呢?我们需要一种可以做到O(1)查询的算法,这时就可以用到ST ...
- SpringAop名词解释+基于xml的配置
1,AOP名词解释 2,AOP演示 (1)导包: (2)准备目标对象 package com.songyan.service; import org.aspectj.lang.ProceedingJo ...
- SYSPROCESSES 查看连接
原文:SYSPROCESSES 查看连接 SELECT at.text,sp.* FROM[Master].[dbo].[SYSPROCESSES] sp CROSS APPLY sys.dm_exe ...
- Spring Bean Life Cycle Methods – InitializingBean, DisposableBean, @PostConstruct, @PreDestroy and *Aware interfaces
Spring Beans are the most important part of any Spring application. Spring ApplicationContext is res ...
- elasticsearch新加入节点不能识别问题
向ES集群中新加入节点,配置文件也没有什么问题,但是就是加不进去,这时候就需要检查一下防火墙是否开启.关闭即可
- zabbix通过percona插件监控mysql
percona zabbix mysql-plugin是percona发布的一个使用zabbix监控mysql数据库的工具,这款工具比zabbix自带的监控模板要强大的多,毕竟percona是Mysq ...
- iptables 使用场景
25 Most Frequently Used Linux IPTables Rules Examples by RAMESH NATARAJAN on JUNE 14, 2011 At a firs ...