struts2错误:HTTP Status 404 - No result defined for action xxx and result error

     今天在做SSH项目的时候遇到了一个错误,错误:HTTP Status 404 - No result defined for action xxx and result error。

我在action中添加了一个保存实体的方法,如下:

/**
    * 添加客户
    * <p>Title: add</p>  
    * <p>Description: </p>  
    * @author Tianyu Xiao  
    * @date 2018年8月26日
    * @return
    */
   public String add() {
	   customerService.save(cust);
	   return "toList";
   }

在action中进行了对Customer的模型驱动参数封装,在jsp中进行了参数封装,如下:

其中action中的getter()和setter()已省略

@Scope("prototype")
public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {
   /** serialVersionUID*/ 
   private static final long serialVersionUID = 1L;
   /**
    * 获取表单参数
    */
   private Customer cust = new Customer();
   @Override
   public Customer getModel() {
      return cust;
   }

在jsp中:

<script type="text/javascript">
//使用ajax加载数据字典,生成select
//参数1: 数据字典类型 (dict_type_code)
//参数2: 将下拉选放入的标签id
//参数3: 生成下拉选时,select标签的name属性值
//参数4: 需要回显时,选中哪个option
	function loadSelect(typecode,positionId,selectname,selectedId) {
 //1创建select对象,并将name属性指定
 var $select = $("<select name="+selectname+"></select>");
 //2添加提示选项
 $select.append($("<option value=''>---请选择---</option>"));
 $.ajax({
    url:"${pageContext.request.contextPath}/baseDictAction",
    async:true,
    type:"POST",
    data:{"dict_type_code":typecode},
    success:function(data) {
       //4 返回json数组对象,对其遍历
       $.each(data, function(i, json) {
          // 每次遍历创建一个option对象
          var $option = $("<option value='"+json['dict_id']+"' >"
                + json["dict_item_name"] + "</option>");
          //判断是否需要回显 ,如果需要使其被选中
          if (json['dict_id'] == selectedId) {
             $option.attr("selected", "selected");
          }
          //并添加到select对象
          $select.append($option);
        //5将封装好的select封装放入指定id的位置
  		$("#" + positionId).append($select);
       });
    },
    dataType : "json"
 });
};
	$(function() {
		loadSelect("006","level","cust_level");
		loadSelect("009","source","cust_source");
		loadSelect("001","industory","cust_industry");
	});
</script>

Customer.java:

private Long cust_id;
	
	private String cust_name;
	/*private String cust_source;
	private String cust_industry;
	private String cust_level;*/
	/**
	 * 对应basedict多对一
	 */
	private BaseDict cust_source;
	private BaseDict cust_industry;
	private BaseDict cust_level;
	
	
	private String cust_linkman;
	private String cust_phone;
	private String cust_mobile;

红色框中指定的是参数封装时的属性,可见与实体中不对应,修改如下:

$(function() {
		loadSelect("006","level","cust_level.dict_id");
		loadSelect("009","source","cust_source.dict_id");
		loadSelect("001","industory","cust_industry.dict_id");
	});

该类错误主要是由于参数没有正确封装引起的。

然而,在晚上又做了一个删除的功能,又报了这个错误,本人检查之后参数封装没有问题,但只要调用service就会出现错误,原因是本人在spring配置了注解事务,默认事务为只读,而在进行删除操作的时候并没有指定readOnly=false,所以又出现了这个错误,加上注解:

/**
	 * 根据id删除
	 */
	@Transactional(readOnly=false)
	public void deleteById(Long id) {
		customerDao.delete(id);
	}

完美解决该问题。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值