求教,实在没搞懂why?
1.SerializeTest.html代码:
<!DOCTYPE html>
<html>
<head>
<title>SerializeTest.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-1.8.3.min.js">
</script>
<script type="text/javascript">
$(function(){
$("form [type='button']").click(function(){
var str=$("form").serialize();
//alert(str);
$("div").load("/Test/serialize?"+str,function(){
alert($("div").val());
});
});
});
</script>
</head>
<body>
<div id="d">
</div>
<form id="f">
用户姓名:<input name="username" type="text">
<br>
密码 :<input name="password" type="text">
<br>
<input value="submit" type="button">
</form>
</body>
</html>
package cn.itcast.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class serialize extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
System.out.println("---");
String username=request.getParameter("username");
String password=request.getParameter("password");
PrintWriter out=response.getWriter();
out.write("用户名是:" + username + "密码是:" + password);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}