JQuery传递form表单数据,java后台获取不了

黑夜小凡 发布于 2015/05/20 09:20
阅读 5K+
收藏 0

前台页面代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>注册</title>
<style type="text/css">
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0}
body,button,input,select,textarea{font:12px/1.5 tahoma,arial,\5b8b\4f53,sans-serif;text-align:justify;text-justify:inter-ideograph;word-break:break-all;word-wrap:break-word}
h1,h2,h3,h4,h5,h6{font-size:100%}
address,cite,dfn,em,var,i,u{font-style:normal}
code,kbd,pre,samp{font-family:courier new,courier,monospace}
small{font-size:12px}ul,ol{list-style:none}
sup{vertical-align:text-top}sub{vertical-align:text-bottom}
legend{color:#000}fieldset,img{border:0}button,input,select,textarea{font-size:100%;padding:0;margin:0}
table{border-collapse:collapse;border-spacing:0}caption,th{ text-align:left }
.ovh{overflow:hidden}.l{float:left}.r{float:right}.cur{cursor:pointer}
.c_b{content:".";display:block;height:0;clear:both;visibility:hidden;zoom:1;font-size:0px;overflow:hidden;visibility:hidden}.c_b2{clear:both}.dn{display:none}.dis{display:block}.b{font-weight:bold}
body{behavior:url("css/hover_htc.htc");font-family:"Microsoft YaHei",宋体; color:#333;}/*hover*/


/*会员注册*/
.login ul{/*background:url(../images/line.png) repeat-x;*/ padding-top:10px; border-top:1px solid #fff}
.login ul a{ color:#005cb1}
.login .id input,.login .pw input,.in_id,.in_mo,.reg_input,.reg_input_pic{background-color:#FFF; border:1px solid #d5cfc2;  font-size:14px; font-weight:bold; vertical-align:middle}
.login .id input,.login .pw input{width:170px; height:30px;margin:0 5px 5px 0; line-height:30px; padding:0 5px;}
.login .id input:hover,.login .pw input:hover,.in_id:hover,.in_mo:hover,.reg_input:hover,.reg_input_pic:hover{border:1px solid #005cb1;background-color:#F2FAFF;}
.l_button,.r_button{background:url(images/login_button.png) no-repeat; width:118px; height:39px; border:none; cursor:pointer; display:block; float:left; text-indent:-9000px}
.l_button{background-position:0 -60px;}
.r_button{background-position:-138px -60px; margin-right:4px}
.l_button:hover{background-position:0 0;}
.r_button:hover{background-position:-138px 0;}
.f_reg_but{margin:10px 0 0 115px}


.reg{width:460px; font-size:14px;line-height:25px; overflow:hidden;}
.reg dl{padding-left:10px; font-size:14px;}
.reg dl dt{ margin-top:15px}
.reg dl dd{padding:3px 0}
.reg .title{width:100px; display:inline-block; text-align:right; padding-right:10px}
.reg_input_pic{width:80px;}
.in_pic_s{margin-left:83px}
.reg .img{position:absolute}
.onShow,.onFocus,.onError,.onCorrect,.onLoad{background:url(images/reg_bg.png) no-repeat 3000px 3000px;padding-left:30px; font-size: 12px; height:25px; width:124px; display:inline-block; line-height:25px; vertical-align:middle; overflow:hidden; margin-left:6px}
.onShow{color:#999; padding-left:0px}
.onFocus{background-position:0px -30px; color:#333}
.onError{background-position:0px -60px; color:#333}
.onCorrect{background-position:0px 0; text-indent:-9000px}
.onLoad{background-position:0px 0}
.reg_m{margin-left:90px}
.clew_txt{display:inline-block; padding:7px  0 0 15px; font-size:12px;}


.id input,.pw input,.in_id,.in_mo,.reg_input,.reg_input_pic{_behavior:url(js/Round_htc.htc);-moz-border-radius:4px;-webkit-border-radius:4px;border-radius:4px; height:25px;}
.user_button a,.pay_but{_behavior:url(js/Round_htc.htc);-moz-border-radius:100px;-webkit-border-radius:100px;border-radius:100px;}


#one1,#one2{display:block; background-color:#e9eed8; padding:5px 0; text-align:center; clear:both; cursor:pointer}
#one2{margin-top:15px}
#one1:hover,#one2:hover{background-color:#d4dfb0}
#one1 span,#one2 span{color:#F00}
</style>


<script src="js/jquery-2.1.0.min.js" type=text/javascript></script>
<script src="js/formValidator_min.js" type="text/javascript" charset="UTF-8"></script>
<script src="js/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<script src="js/reg.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
function userReg(){
$.ajax({
 type: "post",
 url:"../userReg.do", //发送请求€
 dataType: "json",
 data: 'param='+$('#form1').serializ,
 contentType: "application/json;charset=UTF-8",
 success: function(result){
 }
 })
}
</script>
</head>


<body>


<!--注册开始-->
    <div class="reg">
        <form name="form1" id="form1">
            <dl>
                <dd><span class="title">竞投人:</span><input name="bidderName" id="bidderName" class="reg_input" type="text" onblur="return isCnn(this)" /><span id="bidderNameTip" class="onshow"></span></dd>
                <dd><span class="title">证件号:</span><input class="reg_input" name='idCardNum' type='text' id='idCardNum' onblur="return checktheform();" /><span id="idCardNumTip" class="onshow"></span></dd>
                <dd><span class="title">联系人:</span><input class="reg_input" name='name' type='text' id='name' /></dd>
                <dd><span class="title">联系手机:</span><input class="reg_input" name='telphone' type='text' id='telphone' /></dd>
                <dd><span class="title">邮箱地址:</span><input class="reg_input" name="e_mail" type="text" id="e_mail" onblur="checkemail(this.value)" /><span id="e_mailTip" class="onshow"></span></dd>
                <dd><span class="title">联系电话:</span><input class="reg_input" name='phoneCall' type='text' id='phoneCall' /></dd>
                <dd><span class="title">通讯地址:</span><input class="reg_input" name='address' type='text' id='address' /></dd>
                <dd><span class="title">用户名:</span><input class="reg_input" name="userName" id="userName" onblur="checkusername(this.value);" type="text" /><span id="userNameTip" class="onshow"></span></dd>
                <dd><span class="title">密码:</span><input class="reg_input" onblur="return checkpasswd(this);" id="password" name="password" type="password"/><span id="passwordTip" class="onshow"></span></dd>
                <dd><span class="title">确认密码:</span><input onblur="checkdoublepassword();" class="reg_input" type="password" id="t_RePass" name="t_RePass"/><span id="t_RePassTip" class="onshow"></span></dd>
                <dd><span class="title">验证码:</span><input id="t_CheckCode" class="reg_input_pic" name="t_CheckCode" type="text" maxlength="4" /></dd>
            </dl>           
             </form>
            <div class="f_reg_but"><input id="btnSend" name="btnSend" type="submit" value="注册" onclick="userReg()" class="r_button"/><span class="clew_txt">如果您已有帐号,可<a href="login.html">直接登录</a></span></div>                           
    </div>
<!--注册结束-->        
</body>
</html>

后台接收代码:

package com.oking.aruralAssetsManage.controller;


import java.util.List;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import com.oking.aruralAssetsManage.entity.Bidder;


@Controller
public class RegisteController {

@RequestMapping(value="userReg.do",method=RequestMethod.POST)
public @ResponseBody List<Map<String, ?>> getStopSignal(HttpServletRequest request,
HttpServletResponse response,Map<String, Object> param) throws Exception{
  System.out.println("装载"+param.get("userName"));
/*if(param!=null){
    Bidder bi  = new Bidder();
    bi.setBidderName((String) param.get("bidderName"));
   }


}*/
  return null;
}
  


}


在控制台输出的是Null的值,求大神解救

以下是问题补充:

@黑夜小凡:实体类: package com.oking.aruralAssetsManage.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="T_BIDDER") public class Bidder implements Serializable { private static final long serialVersionUID = 1L; private Long id; private String bidderName; private String idCardNum; private String name; private String telphone; private String e_mail; private String phoneCall; private String address; private String userName; private String password; @Id @Column(name="SLBH", nullable = false) @GeneratedValue(strategy=GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(name="BIDDER_NAME",length=50) public String getBidderName() { return bidderName; } public void setBidderName(String bidderName) { this.bidderName = bidderName; } @Column(name="ID_CARD_NUM",length=200) public String getIdCardNum() { return idCardNum; } public void setIdCardNum(String idCardNum) { this.idCardNum = idCardNum; } @Column(name="NAME",length=200) public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name="E_MAIL",length=200) public String getE_mail() { return e_mail; } public void setE_mail(String e_mail) { this.e_mail = e_mail; } @Column(name="TELPHONE",length=200) public String getTelphone() { return telphone; } public void setTelphone(String telphone) { this.telphone = telphone; } @Column(name="ADDRESS",length=500) public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } @Column(name="PHONE_CALL",length=200) public String getPhoneCall() { return phoneCall; } public void setPhoneCall(String phoneCall) { this.phoneCall = phoneCall; } @Column(name="USER_NAME",length=200) public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } @Column(name="PASSWORD",length=200) public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } (2015/05/20 10:47)
加载中
0
不打伞的小鱼
不打伞的小鱼
不是应该有个实体类与页面中的那些属性一一对应,然后在controller里面给get/set方法,然后获取页面传过来的数据吗? Map<> param 这个它怎么知道你是和ajax请求中的对应啊?
0
黑夜小凡
黑夜小凡
是有一个实体类啊,我没放上去而已,那我在后台应该怎么接收他呢?
0
kinnonZhan
kinnonZhan

$.ajax({type: "post",

url:"../userReg.do", //发送请求

€dataType: "json",

data: $('#form1').serialize(),

contentType: "application/json;charset=UTF-8",

success: function(result){

}

)}

黑夜小凡
黑夜小凡
换成这样的写法,后台还是接收不了啊
0
-Jw-
-Jw-
F12 看network的请求有没有传
0
安西都护府首席程序员
安西都护府首席程序员
你data不是这么传的吧。应该是data: $('#form1').serialize()
黑夜小凡
黑夜小凡
我之前就是这样写的,可是后台输出的是null值
0
飞炀
飞炀
把ajax设置里面的contentType去掉
返回顶部
顶部