在jsp页面中可以显示,但控制台上却显示为空值
以下上相关代码:
//servlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String name=request.getParameter("usename");
String pwd=request.getParameter("pwd");
String sex=request.getParameter("sex");
String habbit=request.getParameter("hibbit");
System.out.println("用户名:"+name+",密码:"+pwd+",性别:"+sex+",爱好:"+habbit);
out.print("success");
out.flush();
out.close();
}
//jsp页面
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$("#submit").click(function(){
var inputArray=$('#myform').find(":input");
var paramArray=inputArray.serializeArray();
var uname=$.param(paramArray);
alert(uname);
$.ajax({
url :"serializeServlet",
data :"uname",
success:function(data){
if(data=="success"){
var $comment=$("<tr><td>用户名:</td><td>usename</td></tr>"
+"<tr><td>密码:</td><td>password</td></tr>"
+"<tr><td>性别:</td><td>sex</td></tr>"
+"<tr><td>爱好:</td><td>hibbit</td></tr>");
$(paramArray).each(function(){
$comment.find("td:contains('"+this.name+"')").text(this.value);
});
alert($comment);
$("#tables").prepend($comment);
}
}
});
});
});
</script>
</head>
<body>
<form action="" id="myform">
用户名:<input name="usename"/><br/>
密码: <input type="password" name="pwd"/><br/>
性别:<input type="radio" name="sex" value="男"/>男 <input type="radio" name="sex" value="女"/>女<br/>
爱好:<input type="checkbox" name="hibbit" value="playgame">玩游戏
<input type="checkbox" name="hibbit" value="read">阅读
<input type="checkbox" name="hibbit" value="TV">看电视 <br/>
<input type="button" id="submit" value="提交">
<table id="tables">
</table>
</form>
</body>
Seaweed
Finit
相关分类