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的更多相关文章

  1. 【深入Struts2】获取ServletAPI的三种方式

    一:获取servletAPI的三种方法 在传统的Web开发中,经常会用到Servlet API中的HttpServletRequest.HttpSession和ServletContext.Strut ...

  2. struts2学习笔记--总结获取servletAPI的几种方式

    struts2的Action放弃了request,response等ServletAPI,使得在业务层上更加独立,在有时候使用struts2进行Web开发的时候,不可避免的要在action中使用ser ...

  3. struts2中获取request、response,与android客户端进行交互(文件传递给客户端)

    用struts2作为服务器框架,与android客户端进行交互需要得到request.response对象. struts2中获取request.response有两种方法. 第一种:利用Servle ...

  4. Struts2中获取HttpServletRequest,HttpSession等的几种方式

    转自:http://www.kaifajie.cn/struts/8944.html package com.log; import java.io.IOException; import java. ...

  5. Struts2 后台获取路径的几种方法

    Struts2 后台获取路径的几种方法 package actions.app; import java.io.File; import org.apache.struts2.ServletActio ...

  6. struts2框架学习笔记3:获取servletAPI

    Struts2存在一个对象ActionContext(本质是Map),可以获得原生的request,response,ServletContext 还可以获得四大域对象(Map),以及param参数( ...

  7. Struts2笔记——与ServletAPI解耦

    与ServletAPI解耦的访问方式 为了避免与 Servlet API 耦合在一起, 方便 Action 做单元测试, Struts2 对 HttpServletRequest, HttpSessi ...

  8. Action中获取servletAPI对象的方法

    1.ServletActionContext:可以从中获取当前Action对象需要的一切ServletAPI的相关对象: 常用的方法: 1.获取HttpServletRequest:ServletAc ...

  9. Struts2中获取servlet API的几种方式

    struts2是一个全新的MVC框架,如今被广大的企业和开发者所使用,它的功能非常强大.这给我们在使用servlet 纯java代码写项目的时候带来了福音.但是一般来说,我们的项目不到一定规模并不需要 ...

随机推荐

  1. 03-CSS颜色、文本、字体、边框、背景

    # Css颜色,文本字体 ## css颜色表示法1.颜色名表示,比如:red 红色,gold 金色 2.16进制数值表示,比如:#ff0000 表示红色,这种可以简写成 #f00 3.RGB颜色: 红 ...

  2. http请求中的Content-Length作用机制与分块chunked

    httpclient-4.5.9.jar org.apache.http: auth     身份 client    端 conn     连接 cookie  本地 impl:    实现 exe ...

  3. Kintex 7五兄弟

    基KC705E 增强版 基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡(136) 本板卡是Xilinx公司芯片V5系列芯片设计信号处理板卡.由一 ...

  4. window 批处理脚本获取上级目录

    1 SET CurrDir=%CD% CD.. SET InstPath=%CD% CD %CurrDir% 2 pushd.. set parent=%cd% popd 参考: https://ms ...

  5. 学习旧岛小程序 (4)封装api 请求

    1.配置基本的 请求路径 和 key config.js const config = { baseUrl: 'http://bl.7yue.pro/v1/', appkey: "" ...

  6. 前端每日实战:98# 视频演示如何用纯 CSS 创作一只愤怒小鸟中的绿猪

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/VBGWqX 可交互视频 此视频是可 ...

  7. MyBatis体系学习总览

    MyBatis特点:MyBatis是面向SQL的,核心是SQL结果和Map的映射.不要求一定与实体对象进行映射. MyBatis 可以使用 XML 或注解进行配置和映射, MyBatis 通过将参数映 ...

  8. 【leetcode】1078. Occurrences After Bigram

    题目如下: Given words first and second, consider occurrences in some text of the form "first second ...

  9. HTTP通信安全和Web攻击技术

    一.HTTPS,确保Web安全 在HTTP协议中可能存在信息窃听或身份伪装等安全问题,HTTP的不足: 通信使用明文(不加密),内容可能会被窃听  不验证通信方的身份,因此有可能遭遇伪装 无法证明报文 ...

  10. Access分页语句

    一.双TOP法高效率的Access分页的SQL语句,语法格式: SELECT * FROM (SELECT TOP "&pagesize&" * FROM (SEL ...