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. 输vim /etc/rc.d/init.d/mysqld 报错 …..localdomain.pid

    在安装MySQL的过程中出现以下错误: 本人解决方法是: ps aux | grep mysqld 罗列出所有关于mysqld的进程,然后把关于mysqld的进程都kill了.

  2. Wireshark中的结果分析

    Header checksum: 0x9899 [validation disabled] 因为,wireshark不自动做tcp校验和的检验.原因是因为:有时tcp校验和会由网卡计算,因此wires ...

  3. bzoj3589 动态树 树链剖分+容斥

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3589 题解 事件 \(0\) 不需要说,直接做就可以了. 事件 \(1\) 的话,考虑如果直接 ...

  4. 【leetcode】1091. Shortest Path in Binary Matrix

    题目如下: In an N by N square grid, each cell is either empty (0) or blocked (1). A clear path from top- ...

  5. tensorflow函数介绍(4)

    1.队列的实现: import tensorflow as tf q=tf.FIFOQueue(2,'int32') #创建一个先进先出队列,指定队列中最多可以保存两个元素,并指定类型为整数. #先进 ...

  6. Springboot ,1开启配置与2.扫描包(控制层,service层)二个注解@EnableAutoConfiguration,@ComponentScan 合并成一个注解@SpringBootApplication

    //@EnableAutoConfiguration//@ComponentScan(value= {"com.foen.cloud.controller.*","com ...

  7. 一道装呀(状压)DP

    generator 题目描述: 自己的数学太差了,居然没看出来和这两个是相同的: 啊啊啊: 所以装呀一下就好了: #include<iostream> #include<cstdio ...

  8. Linux 系统下文件夹与文件的读写可执行权限问题

    linux是一个多用户操作系统,linux对文件系统内的所有文件,实行了严格的权限划分管理.防止没有权限的用户访问某个文件.linux文件或目录的权限分为 读.写.可执行三种权限.文件访问的用户类别分 ...

  9. VMware Workstation 官方正式版及激活密钥

    热门虚拟机软件VMware Workstation Pro现已更新至14.1.2,14.0主要更新了诸多客户机操作系统版本,此外全面兼容Wind10创建者更新.12.0之后属于大型更新,专门为Win1 ...

  10. Flask学习 3 url_for的使用

    #!/usr/bin/env python # encoding: utf-8 """ @version: v1.0 @author: cxa @file: flask0 ...