Struts2之获取ServletAPI
1.通过ServletActionContext类
//获取request对象
HttpServletRequest request = ServletActionContext.getRequest();
//保存值到application中
ServletActionContext.getActionContext(request).setApplication(new HashMap<>());
2.通过ServletRequestAware 接口
public class UserAction extends ActionSupport implements ServletRequestAware {
private String username;
private String userpwd;
private HttpServletRequest request;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpwd() {
return userpwd;
}
public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
}
@Override
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
public void executeAjax() throws IOException {
// 处理Ajax请求
String name = request.getParameter("username");
String pwd = request.getParameter("userpwd");
HttpServletResponse response = ServletActionContext.getResponse();
response.getWriter().print("hello"+username+"hello"+userpwd);
}
}
Struts2之获取ServletAPI的更多相关文章
- 【深入Struts2】获取ServletAPI的三种方式
一:获取servletAPI的三种方法 在传统的Web开发中,经常会用到Servlet API中的HttpServletRequest.HttpSession和ServletContext.Strut ...
- struts2学习笔记--总结获取servletAPI的几种方式
struts2的Action放弃了request,response等ServletAPI,使得在业务层上更加独立,在有时候使用struts2进行Web开发的时候,不可避免的要在action中使用ser ...
- struts2中获取request、response,与android客户端进行交互(文件传递给客户端)
用struts2作为服务器框架,与android客户端进行交互需要得到request.response对象. struts2中获取request.response有两种方法. 第一种:利用Servle ...
- Struts2中获取HttpServletRequest,HttpSession等的几种方式
转自:http://www.kaifajie.cn/struts/8944.html package com.log; import java.io.IOException; import java. ...
- Struts2 后台获取路径的几种方法
Struts2 后台获取路径的几种方法 package actions.app; import java.io.File; import org.apache.struts2.ServletActio ...
- struts2框架学习笔记3:获取servletAPI
Struts2存在一个对象ActionContext(本质是Map),可以获得原生的request,response,ServletContext 还可以获得四大域对象(Map),以及param参数( ...
- Struts2笔记——与ServletAPI解耦
与ServletAPI解耦的访问方式 为了避免与 Servlet API 耦合在一起, 方便 Action 做单元测试, Struts2 对 HttpServletRequest, HttpSessi ...
- Action中获取servletAPI对象的方法
1.ServletActionContext:可以从中获取当前Action对象需要的一切ServletAPI的相关对象: 常用的方法: 1.获取HttpServletRequest:ServletAc ...
- Struts2中获取servlet API的几种方式
struts2是一个全新的MVC框架,如今被广大的企业和开发者所使用,它的功能非常强大.这给我们在使用servlet 纯java代码写项目的时候带来了福音.但是一般来说,我们的项目不到一定规模并不需要 ...
随机推荐
- 关于使用itext转Html为pdf添加css样式的问题
使用的jar文件 xmlworker-5.5.11.jar itextpdf-5.5.11.jar 下载地址:https://pan.baidu.com/s/1i5AIBvZ 以下为测试代码 pack ...
- 通过busybox制作根文件系统
通过busybox制作根文件系统可以自定义选项,在制作的根文件系统中添加需要的命令,指定生成的根文件系统到相应的目录下. 一. 根文件系统的获取方式--->官网: https://busybox ...
- selenium下拉菜单
from selenium.webdriver.support.select import Selectdef select_value(self, css, value): ''' 选中 ...
- java并发学习--第一章 线程的创建
所谓的并发就是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行.所以我们看似几个线程在同时进行,其实在操作系统中 ...
- layui树形表格支持非异步和异步加载
layui树形表格支持非异步和异步加载. 仓库地址:https://gitee.com/uniqid/ 使用示例如下: <div class="uui-admin-common-bod ...
- opencv 环境配置-windowsx64 +VS2017
opencv版本为4.1.1官方最新版本, https://sourceforge.net/projects/opencvlibrary/ 先配置本地工程环境: 右键我的电脑-属性 将bin的路径添加 ...
- Task7.卷积神经网络
卷积定义: 所谓卷积,其实是一种数学运算.但是在我们的学习生涯中,往往它都是披上了一层外衣,使得我们经常知其然不知其所以然.比如在信号系统中,他是以一维卷积的形式出现描述系统脉冲响应.又比如在图像处理 ...
- Python3及Pycharm安装
1.首先去python官网下载相应版本的Python安装包.如下: 2.下载完成后解压,双击exe文件进行安装,看到如下界面:Install Now表示默认安装:Customize installat ...
- C#语句,console,C#//,/**/
].
- php key()函数 语法
php key()函数 语法 作用:返回数组内部指针当前指向元素的键名.大理石构件支架 语法:key(array) 参数: 参数 描述 array 必需.规定要使用的数组. 说明:返回数组内部指针当前 ...