• Struts2 中遇到的问题


    1. 

    警告: Could not find action or result: /Struts2Test/register.action
    There is no Action mapped for namespace [/] and action name [register] associated with context path [/Struts2Test]. - [unknown location]

    struts.xml 文件放错位置 因为创建的是maven项目 struts.xml应该放在src/main/resource 目录下 

    项目启动后 D:apache-tomcat-8.0.23webappsStruts2TestWEB-INFclasses 目录下会有struts.xml 文件 

    2.

    十月 15, 2015 10:35:22 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
    严重: Developer Notification (set struts.devMode to false to disable this message):
    Unexpected Exception caught setting 'name' on 'class Action.RegisterAction: Error setting expression 'name' with value ['78457645', ]

    jsp页面提交form表单 struts Action类 用下面这种方式获得不了form表单提交的内容

    package Action;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class RegisterAction extends ActionSupport{
            
        public String execute(String name,String sex,String phone,String password, HttpServletRequest request) {
            List list = new ArrayList();
            list.add(name);
            list.add(sex);
            list.add(phone);
            list.add(password);
            System.out.println(name + sex + phone +password);
            if(name != null && password != null){
            request.getSession().setAttribute("name"+name, list);
            System.out.println(request.getSession());
            return "success";
            }
            return "success";
        }
    }

    需要在Action类中 添加form表单中提交字符串作为Action的属性 并提供getter setter方法

    package Action;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class RegisterAction extends ActionSupport{
        
        private String name;
        private String sex;
        private String phone;
        private String password;
        private HttpServletRequest request;
        
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getSex() {
            return sex;
        }
    
        public void setSex(String sex) {
            this.sex = sex;
        }
    
        public String getPhone() {
            return phone;
        }
    
        public void setPhone(String phone) {
            this.phone = phone;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public HttpServletRequest getRequest() {
            return request;
        }
    
        public void setRequest(HttpServletRequest request) {
            this.request = request;
        }
        
        public String execute(HttpServletRequest request) {
            List list = new ArrayList();
            list.add(name);
            list.add(sex);
            list.add(phone);
            list.add(password);
            System.out.println(name + sex + phone +password);
            if(name != null && password != null){
            request.getSession().setAttribute("name"+name, list);
            System.out.println(request.getSession());
            return "success";
            }
            return "success";
        }
    }
  • 相关阅读:
    SQLite在iOS开发中的使用
    实现序列化和反序列化
    NSPredicate用于对集合类中的元素进行筛选
    通知中心NSNotification与委托的异同,需要注意的要点
    OC 重写description,isEqual方法
    iOs 单例模式的定义,实现、步骤
    Obejctiv-c 里面KVC 和 KVO的实现步骤,和有关方法
    关于NSTimer的几种构建方式
    NSTimer 实现到一个指定时间(年、月、日)的倒计时
    关于UILable、UIButton、UITextField简单运用
  • 原文地址:https://www.cnblogs.com/weixiaole/p/4881676.html
Copyright © 2020-2023  润新知