• day8——ajax传参到action(Struts2)


    第一种:url+?+参数

    jsp中:

    $(function(){
      $("[name='delemp']").click(function(){
      $this = $(this);
      $delid = $this.attr("delid");
      if(confirm("确认删除该条数据吗?")){
        $.ajax({
          type:"get",
          url:"deleteemployeebyid?delid="+$delid,
          dataType:"json",
          success:function(msg){
            $this.parent().parent().parent().remove();
            alert(msg);
        }
        });
      }else{
      return false;
    }
    })

    action中:

    public String delEmployeesById(){
      Map<String,Object> map = ActionContext.getContext().getParameters();
      Object[] delid = (Object[]) map.get("delid");
      String deleteid = (String) delid[0];
      Integer did = Integer.valueOf(deleteid);
      Employees emp = new Employees();
      emp.setId(did);
      employeesService.deleteEmployeeById(emp);
      return SUCCESS;
    }

    第二种:post请求传递,action属性接收(推荐

    jsp:

      ………………

      $.ajax({
          type:"post",
          url:"deleteemployeebyid,
          dataType:"json",

          data:{"delId":$delid},
          success:function(msg){
            $this.parent().parent().parent().remove();
            alert(msg);
        }

      ………………

    action:

    private Integer delId;

    getter/setter方法

    private String jsonobj;  //删除success后返回的msg

    getter/setter

    ………………具体方法中直接用delId

    struts.xml:(json结果配置)

    <!-- json响应,返回单个Object -->
    <result name="retJsonObj" type="json">
      <param name="root">jsonObj</param>
    </result>

  • 相关阅读:
    idea找不到或无法加载主类
    Scala核心编程_第09章 面向对象编程(高级特性)
    spring源码:学习线索
    Redis
    spring源码:Aware接口
    spring源码:核心组件(li)
    java socket编程
    spring源码:ApplicationContext的增强功能(li)
    spring源码:web容器启动
    spring源码:BeanPostProcessor(li)
  • 原文地址:https://www.cnblogs.com/whisper527/p/6523313.html
Copyright © 2020-2023  润新知