zoukankan      html  css  js  c++  java
  • 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);
            
        }
    
        }
    
    
    
  • 相关阅读:
    法正(17):玄德
    法正(16):舌战
    法正(15):卢氏
    法正(14):寿星
    struts2笔记---struts2的执行过程
    Oracle数据库(一)
    flask的使用(一)
    struts2--笔记(一)
    docker基础(二)
    docker安装及问题处理
  • 原文地址:https://www.cnblogs.com/jiangwenwen1/p/9461608.html
Copyright © 2011-2022 走看看