NutzCN Logo
问答 我就是改一个一模一样的方法 就无法添加成功了 麻烦大神看一下 页面的值根本去不了后台
发布于 2276天前 作者 qq_183ceadf 1577 次浏览 复制 上一个帖子 下一个帖子
标签:
(index):148 Uncaught ReferenceError: base is not defined
    at HTMLButtonElement.<anonymous> ((index):148)
    at HTMLButtonElement.dispatch (jquery-latest.js:4641)
    at HTMLButtonElement.elemData.handle (jquery-latest.js:4309)
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>配置ixnx</title>
</head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function() {
	
	var pageNumber = 1;
    var pageSize = 10;
    var base = '<%=request.getAttribute("base")%>';
    $('#sjsh_ext').hide();
    $('#sjsh_ext1').hide();
    ris_reload();
    function ris_reload() {
        $.ajax({
            url : base + "/user/query1",
           
            data : $("#ris_query_form").serialize(),
            dataType : "json",
            type:"post",
            success : function(data) {
              //  console.log(data);
               var di=$('#change_list');
                var list_html = "";
                for (var i=0;i<data.list.length;i++) {
                    var ris = data.list[i];
                    var str='';
                    
                  var str = "<td>" +ris.name +"<input type='text' name='name'>"+
                  " </td><td>"+ris.idcode+"<input type='text' name='idcide'>"+"</td>"
                  +"<tr><td>"+ ris.Education11
                  	+"<select><option name='education'>"+ris.Education+"</option>"
                  		+"<option name='education1'>"+ris.Education1+"</option>"
                  		+"<option name='education2'>"+ris.Education2
                  		+"</option></select>"+"</td><td>"+ris.Marriage11
                  		+"<select><option name='marriage'>"+ris.Marriage+"</option>"
                  		+"<option name='marriage1'>"+ris.Marriage1+"</option>"
                  		+"<option name='marriage2'>"+ris.Marriage2+"</option></select></td></tr><tr><td>"
                  	+ris.children11
            		+"<select><option  name='children'>"+ris.children+"</option>"
              		+"<option name='children1'>"+ris.children1+"</option></select></td><td>"
              		+ris.family_assets11
            		+"<select><option name='family_assets'>"+ris.family_assets+"</option>"
              			+"<option name='family_assets1'>"+ris.family_assets1+"</option>"
              			+"<option name='family_assets2'>"+ris.family_assets2+"</option>"
              			+"<option name='family_assets3'>"+ris.family_assets3+"</option>"
              			+"<option name='family_assets4'>"+ris.family_assets4+"</option>"
              			+"<option name='family_assets5'>"+ris.family_assets5+"</option>"
              			+"<option name='family_assets6'>"+ris.family_assets6+"</option>"
                   +"</select></td></tr><tr><td>"
                   	 +ris.family_income11
                   	 	+"<select><option name='family_income'>"+ris.family_income+"</option>"
           				+"<option name='family_income1'>"+ris.family_income1+"</option>"
          				+"<option name='family_income2'>"+ris.family_income2+"</option>"
          				+"<option name='family_income3'>"+ris.family_income3+"</option>"
          				+"<option name='family_income4'>"+ris.family_income4+"</option>"
          				+"<option name='family_income5'>"+ris.family_income5 +"</option>"
          			 +"</select></td><td>"+ris.family_debt11
          				+"<select><option name='family_debt'>"+ris.family_debt+"</option>"
       					+"<option name='family_debt1'>"+ris.family_debt1+"</option>"
      					+"<option name='family_debt2'>"+ris.family_debt2+"</option>"
      					+"<option name='family_debt3'>"+ris.family_debt3+"</option>"
      					+"<option name='family_debt4'>"+ris.family_debt4+"</option>"
                   +"</select></td></tr><tr><td rowspan='2'>"+ris.Letter+"</td><td>"
                   		+ris.Letter1+"<select><option name='overdue_days'>"+ris.overdue_days+"</option>"
           				+"<option name='overdue_days1'>"+ris.overdue_days1+"</option>"
          				+"<option name='overdue_days2'>"+ris.overdue_days2+"</option>"
          				+"<option name='overdue_days3'>"+ris.overdue_days3+"</option>"
          				+"<option name='overdue_days4'>"+ris.overdue_days4+"</option>"
          				+"<option name='overdue_days5'>"+ris.overdue_days5+"</option>"
          				+"<option name='overdue_days6'>"+ris.overdue_days6+"</option>"
          				+"<option name='overdue_days7'>"+ris.overdue_days7+"</option>"
          			 +"</select></td></tr><tr><td>"+ris.Letter2
          			 +"<select><option name='overdue_number'>"+ris.overdue_number+"</option>"
           				+"<option name='overdue_number1'>"+ris.overdue_number1+"</option>"
          				+"<option name='overdue_number2'>"+ris.overdue_number2+"</option>"
          				+"<option name='overdue_number3'>"+ris.overdue_number3+"</option>"
          				+"<option name='overdue_number4'>"+ris.overdue_number4+"</option>"
          				+"<option name='overdue_number5'>"+ris.overdue_number5+"</option>"
                   +"</select></td></tr><tr><td>"+ris.xm
                   +"<select onchange='dqchange(this)'><option value='car'>"+" "+"</option>"
      				   +"<option value='car1'>"+ris.hosxm+"</option>"
      				 +"<option value='car2'>"+ris.carxm+"</option>"
               		   +"</select></td></tr><tr ><td><div id='sjsh_ext'><tr><td>"
               		   +ris.region11+"<select><option name='region'>"+ris.region+"</option>"
               		   		+"<option name='region1'>" +ris.region1+"</option>"
               		   		+"<option name='region2'>" +ris.region2+"</option>"
               		 		+"<option name='region3'>" +ris.region3+"</option>"
               				+"<option name='region4'>" +ris.region4+"</option>"
               				+"<option name='region5'>" +ris.region5+"</option>"
               			+"</select></td><td>"+ris.position11
               			+ "<select><option name='position'>"+ris.position+"</option>"
           		   			+"<option name='position1'>" +ris.position1+"</option>"
           		   			+"<option name='position2'>" +ris.position2+"</option></select></td></tr><tr><td>"
           		   			+ris.area11+"<select><option name='area'>"+ris.area+"</option>"
           		   			+"<option name='area1'>" +ris.area1+"</option></select></td><td>"
           		 			+ris.homeyears11+"<select><option name='homeyears'>"+ris.homeyears+"</option>"
           		 		+"<option name='homeyears1'>" +ris.homeyears1+"</option>"
           		 		+"<option name='homeyears2'>" +ris.homeyears2+"</option>"
           				+"<option name='homeyears3'>" +ris.homeyears3+"</option></select></td></tr><tr><td>"
           				+ris.elevator1+"<select><option name='elevator'>"+ris.elevator+"</option>"
           				+"<option name='elevator1'>" +ris.elevator1+"</option></select></td><td>"
           				+ris.renovation11+"<select><option name='renovation'>"+ris.renovation+"</option>"
           				+"<option name='renovation1'>" +ris.renovation1+"</option>"
           		 		+"<option name='renovation2'>" +ris.renovation2+"</option></select></td></tr><tr><td>"
           		 		+ris.land11+"<select><option name='land'>"+ris.land+"</option>"
           		 		+"<option name='land1'>" +ris.land1+"</option></select></td><td>"
           		 		+ris.living11+"<select><option name='living'>"+ris.living+"</option>"
           		 	+"<option name='living1'>" +ris.living1+"</option></select></td></tr>"
           		   			
               		   +"</div></td></tr><tr ><div id='sjsh_ext1'>"+34+"</div></td></tr>"
                   list_html +='<tr>' +str+'</tr>';
                //alert(tmp );
                }
                di.html(list_html);
            }
        
        
        });
    }
})
function dqchange(select) {


var val = $(select).val();
if (val=='car1') {
	$('#sjsh_ext').show();
	$('#sjsh_ext1').hide();
}else if (val =='car2') {
	$('#sjsh_ext').hide();
	$('#sjsh_ext1').show();
}else if(val == 'car'){
$('#sjsh_ext').hide();
$('#sjsh_ext1').hide();
}
}


$(function() {
    
   
    $("#men_button1").click(function() {
        $.ajax({
            url : base + "/user/add1",
            data : $("#ris_add_form1").serialize(),
            dataType : "json",
            success : function(data) {
                if (data.ok) {
                   
                    alert("添加成功");
                } else {
                    alert(data.msg);
                }
            }
        });
    });
});



</script>
<style>
body{
margin-left:auto;
margin-right:auto;
text-align: center;
}
table{

margin-left:auto;
margin-right:auto;
}
</style>
<body >
<form action="" id="ris_add_form1" method="post">
	
    
    <table id="change_list">
  		
    </table>
    
  <button id="men_button1">提交</button>
</form>
   
</body>
</html>
package net.com.module;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.nutz.dao.Cnd;

import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;

import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Attr;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.filter.CheckSession;

import net.com.bean.Business;
import net.com.bean.Problem;
import net.com.bean.User;
@Filters(@By(type=CheckSession.class, args={"me", "/"}))
@IocBean // 还记得@IocBy吗? 这个跟@IocBy有很大的关系哦
@At("/user")
@Ok("json:{locked:'password|salt',ignoreNull:true}")
@Fail("http:500")
public class UserModule extends BaseModule{

    
    
    @At
    public int count() {
        return dao.count(User.class);
    }
    @At
    @Filters()
    public Object login(@Param("username")String name, @Param("password")String password, HttpSession session) {
        User user = dao.fetch(User.class, Cnd.where("name", "=", name).and("password", "=", password));
        if (user == null) {
            return false;
        } else {
            session.setAttribute("me", user.getId());
            return true;
        }
    }
    
    @At
    @Ok(">>:/")
    public void logout(HttpSession session) {
        session.invalidate();
    }
    
    protected String checkUser(User user, boolean create) {
        if (user == null) {
            return "空对象";
        }
        if (create) {
            if (Strings.isBlank(user.getName()) || Strings.isBlank(user.getPassword()))
                return "用户名/密码不能为空";
        } else {
            if (Strings.isBlank(user.getPassword()))
                return "密码不能为空";
        }
        String passwd = user.getPassword().trim();
        if (6 > passwd.length() || passwd.length() > 12) {
            return "密码长度错误";
        }
        user.setPassword(passwd);
        if (create) {
            int count = dao.count(User.class, Cnd.where("name", "=", user.getName()));
            if (count != 0) {
                return "用户名已经存在";
            }
        } else {
            if (user.getId() < 1) {
                return "用户Id非法";
            }
        }
        if (user.getName() != null)
            user.setName(user.getName().trim());
        return null;
    }
    @At
    public Object add(@Param("..")User user) {
        NutMap re = new NutMap();
        String msg = checkUser(user, true);
        if (msg != null){
            return re.setv("ok", false).setv("msg", msg);
        }
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        user = dao.insert(user);
        return re.setv("ok", true).setv("data", user);
    }
    @At
    public Object update(@Param("..")User user) {
        NutMap re = new NutMap();
        String msg = checkUser(user, false);
        if (msg != null){
            return re.setv("ok", false).setv("msg", msg);
        }
        user.setName(null);// 不允许更新用户名
        user.setCreateTime(null);//也不允许更新创建时间
        user.setUpdateTime(new Date());// 设置正确的更新时间
        dao.updateIgnoreNull(user);// 真正更新的其实只有password和salt
        return re.setv("ok", true);
    }
    @At
    public Object delete(@Param("id")int id, @Attr("me")int me) {
        if (me == id) {
            return new NutMap().setv("ok", false).setv("msg", "不能删除当前用户!!");
        }
        dao.delete(User.class, id); // 再严谨一些的话,需要判断是否为>0
        return new NutMap().setv("ok", true);
    }
    @At
    public Object query(@Param("name")String name, @Param("..")Pager pager) {
        Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
        QueryResult qr = new QueryResult();
        qr.setList(dao.query(User.class, cnd, pager));
        pager.setRecordCount(dao.count(User.class, cnd));
        qr.setPager(pager);
        return qr; //默认分页是第1页,每页20条
    }
    
    @At
    public Object query1(@Param("name")String name, @Param("..")Pager pager) {
        Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
        QueryResult qr = new QueryResult();
        qr.setList(dao.query(Problem.class, cnd, pager));
        pager.setRecordCount(dao.count(Problem.class, cnd));
        System.out.println(cnd);
        qr.setPager(pager);
        return qr; //默认分页是第1页,每页20条
    }
    
    protected String checkbu(Business bu, boolean create) {
		 String idcode = bu.getIdcode().trim();
		bu.setIdcode(idcode);
		if (create) {
           int count = dao.count(Business.class, Cnd.where("idcodde", "=", bu.getIdcode()));
           if (count != 0) {
               return "该身份证已经存在";
           }
       }
		 if (bu.getIdcode() != null)
	            bu.setIdcode(bu.getIdcode().trim());
		 return null;
	 }
    
    @At
    public Object add1(@Param("..")Business Business) {
        NutMap re = new NutMap();
        String msg = checkbu(Business, true);
        if (msg != null){
            return re.setv("ok", false).setv("msg", msg);
        }
        Business.setCreateTime(new Date());
        Business.setUpdateTime(new Date());
        Business = dao.insert(Business);
        return re.setv("ok", true).setv("data", Business);
    }
    @At("/")
    @Ok("jsp:jsp.user.lt") // 真实路径是 /WEB-INF/jsp/men/lt.jsp
    public void index1() {
    }
    
    @At("/")
    @Ok("jsp:jsp.user.list") // 真实路径是 /WEB-INF/jsp/user/list.jsp
    public void index() {
    }

}
4 回复

如果连接到用户的新增 就可以 这个就不行 很纠结

放在最前面

var base = '${base}';
function(...) {

};

不要在function里面

添加回复
请先登陆
回到顶部