Struts2之获取ServletAPI
2024-10-07 08:30:50
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);
}
}
最新文章
- asp.net 生成 excel导出保存时, 解决迅雷下载aspx页面问题
- mvc+ef中比较数据
- Android开发指南-框架主题-安全和许可
- MJRefresh插件引起的错误
- Astyle:代码格式化工具简明指南
- Android基础知识巩固:关于PendingIntent和广播
- Python开发规范
- 汉化DevExpress
- 14、Redis的复制
- golang sqrt error练习
- hive 下篇
- 不同tab下的列表长度不同,tab的样式和底部的位置不同
- Spring中常用的注解(@Entity,@Table,@Column,@Repository,@Service)
- 201621123010《Java程序设计》第3周学习总结
- Linux环境编程之IPC进程间通信(五):Posix消息队列1
- Selenium2+python自动化-操作浏览器基本方法
- Spring AOP 整理
- SDOI2012 Round1 day2 集合(set)解题报告
- 零基础学 JavaScript 全彩版 明日科技 编著
- vue项目设置每个页面的title