出现这个错误我的是由于在使用struts2框架 时候使用模型驱动封装页面传来的参数时,没有给对象生成get set方法,给忘记了,还要实现getModel方法,返回对象,并且struts.xml中配置的action方法一定要存在于Action中
模型驱动封装参数正确的Action如下:
package cn.itheima.param;
import java.util.Date;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
//struts2如何获得参数
//属性驱动获得参数
import com.opensymphony.xwork2.ModelDriven;
import cn.itheima.domain.User;
//3.模型驱动
//缺陷:只能返回一个对象
//1->实现接口
public class DemoAction1 extends ActionSupport implements ModelDriven<User>{
/*
* 页面设置<input type='text' name='name'/> 页面跟以前一样
* */
private User user=new User();//3->准备一个user对象 需要创建出对象来
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String execute() throws Exception {
return SUCCESS;
}
//2->实现方法返回对象
@Override
public User getModel() {
// TODO Auto-generated method stub
return user;
}
}
配置struts.xml (注意包名和方法名)
<package name="crm" namespace="/" extends="struts-default">
<action name="CustomerAction_*" class="cn.itheima.web.action.CustomerAction" method="{1}">
<result name="list" type="dispatcher">/jsp/customer/list.jsp</result>
<result name="toList" type="redirectAction">
<param name="actionName">CustomerAction_list</param>
<param name="namespace">/</param>
</result>
</action>
<action name="UserAction_*" class="cn.itheima.web.action.UserAction" method="{1}">
<result name="toHome" type="redirect">/index.htm</result>
</action>
</package>