当前位置:   article > 正文

【java-bug】Exception occurred during processing request:_exception occurred during processing request: fail

exception occurred during processing request: failed to invoke the method sa

出现这个错误我的是由于在使用struts2框架 时候使用模型驱动封装页面传来的参数时,没有给对象生成get set方法,给忘记了,还要实现getModel方法,返回对象,并且struts.xml中配置的action方法一定要存在于Action中

模型驱动封装参数正确的Action如下:

  1. package cn.itheima.param;
  2. import java.util.Date;
  3. import java.util.Map;
  4. import com.opensymphony.xwork2.ActionContext;
  5. import com.opensymphony.xwork2.ActionSupport;
  6. //struts2如何获得参数
  7. //属性驱动获得参数
  8. import com.opensymphony.xwork2.ModelDriven;
  9. import cn.itheima.domain.User;
  10. //3.模型驱动
  11. //缺陷:只能返回一个对象
  12. //1->实现接口
  13. public class DemoAction1 extends ActionSupport implements ModelDriven<User>{
  14. /*
  15. * 页面设置<input type='text' name='name'/> 页面跟以前一样
  16. * */
  17. private User user=new User();//3->准备一个user对象 需要创建出对象来
  18. public User getUser() {
  19. return user;
  20. }
  21. public void setUser(User user) {
  22. this.user = user;
  23. }
  24. public String execute() throws Exception {
  25. return SUCCESS;
  26. }
  27. //2->实现方法返回对象
  28. @Override
  29. public User getModel() {
  30. // TODO Auto-generated method stub
  31. return user;
  32. }
  33. }

配置struts.xml (注意包名和方法名)

  1. <package name="crm" namespace="/" extends="struts-default">
  2. <action name="CustomerAction_*" class="cn.itheima.web.action.CustomerAction" method="{1}">
  3. <result name="list" type="dispatcher">/jsp/customer/list.jsp</result>
  4. <result name="toList" type="redirectAction">
  5. <param name="actionName">CustomerAction_list</param>
  6. <param name="namespace">/</param>
  7. </result>
  8. </action>
  9. <action name="UserAction_*" class="cn.itheima.web.action.UserAction" method="{1}">
  10. <result name="toHome" type="redirect">/index.htm</result>
  11. </action>
  12. </package>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/213927
推荐阅读
相关标签
  

闽ICP备14008679号