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"; } }