- 论坛徽章:
- 0
|
帮看看吧
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <%@ page language="java" contentType="text/html;charset=gb2312"%>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=GB2312" />
- <script language="javascript">
- var xmlHttp;
- function createXMLHttpRequest()
- {
- if(window.ActiveXObject)
- {
- xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- else if(window.XMLHttpRequest)
- {
- xmlHttp = new XMLHttpRequest();
- }
- }
- function createQueryString()
- {
- var userAge = document.form1.userAge.value;
- var userNation = document.form1.userNation.value;
- var result = "userAge="+userAge+"&userNation="+userNation;
- return result;
- }
- function doRequestPost()
- {
- createXMLHttpRequest();
- var url = "ajaxpostcheck.jsp";
- var result = createQueryString();
- xmlHttp.open("POST",url,true);
- xmlHttp.onreadystatechange = handleStateChange;
- xmlHttp.send(result);
- }
- function handleStateChange()
- {
- if(xmlHttp.readyState == 4)
- {
- if(xmlHttp.status == 200)
- {
- alert(xmlHttp.responseText);
- }
- else
- {
- alert("您所请求的页面有误...");
- }
- }
- }
- </script>
- <title>ajax向服务器传送数据post</title>
- </head>
- <body>
- <form name="form1" action="#">
- 年龄:<input type="text" name="userAge"><br>
- 籍贯:<input type="text" name="userNation"><br>
- <input type="button" value="提交" onClick="doRequestPost()"/>
- </form>
- </body>
- </html>
复制代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <%@ page language="java" contentType="text/html;charset=gb2312"%>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=GB2312" />
- <title>获取数据</title>
- </head>
- <body>
- <%
- String userAge = request.getParameter("userAge");
- String userNation = request.getParameter("userNation");
-
- if("26".equals(userAge))
- {
- out.println("26岁");
- out.println("年龄->"+userAge);
- }
- else
- {
- out.println("不是26岁");
- out.println("年龄->"+userAge);
- }
- %>
- </body>
- </html>
复制代码
返回的是null,感觉上没错呀,有空的帮看看吧,谢谢了 |
|