由于项目里面需要用到Java调用PHP的充值接口,所以学习了一下,以下这个Demo是个小小的例子,写下来做个笔记>

jsp页面:

 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"
contentType="text/html; charset=GBK"%> <%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!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>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="x-ua-compatible" content="ie=7" /> <title>Lost Crown</title>
<link rel="icon" href="favicon.ico" />
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript">
function getXmlHttp(){
var http_request = false;
if (window.XMLHttpRequest){
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType){
http_request.overrideMimeType('text/xml');
}
}else if (window.ActiveXObject){
try{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) {
}
}
}
if (!http_request){
alert("不能创建对象!");
return false;
}
return http_request;
} function result(){
if(req.readyState == 4 && req.status == 200){
var names = req.responseText;
alert("Hello:"+names);
}
} function checkTest(){
var name = document.getElementById("name").value;
var ul = "http://localhost:8011/TestAjax/index.php?name=" + name;
req = getXmlHttp();
req.onreadystatechange = result;
req.open("POST",ul,true);
req.setRequestHeader('If-Modified-Since', '0');
req.send(null);
}
</script>
</head>
<body>
<center>
<table width="300" border=1>
<tr align="center">
<td colspan="2">
It's A Ajax Test
</td>
</tr>
<tr align="center">
<td>
用户名
</td>
<td>
<input type="text" name="name" id="name" value="Jerry"/>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="button" name="submit" id="submit" value="提交" onclick="checkTest();"/>
</td>
</tr>
</table>
</center>
</body>
</html>

php页面:

<?php

$username = $_REQUEST['name'];

echo($username);

?>

最新文章

  1. ASP.NET Web API 2 入门
  2. Linux里设置环境变量的方法(export PATH)
  3. Platform Invoke
  4. Struts2再爆远程代码执行漏洞
  5. 转:一个跨WINDOWS LINUX平台的线程类
  6. Html内容超出标记宽度后自动隐藏
  7. CocoaPods对于不同Target引入不同的第三方库Podfile的写法
  8. Codeforces Round #246 (Div. 2)
  9. 高考志愿填报:java 软件 程序员 目前的就业现状
  10. I2C与SMBus
  11. CLOSE_WAIT状态的原因与解决方法
  12. Python Machine Learning-Chapter3
  13. Java 复习
  14. python 列表返回重复数据的下标
  15. 〖Android〗我的ADT Eclipse定制
  16. html 用一个frame刷新另一个frame(同一个Frameset中)
  17. 安装zabbix3.4的过程(一)
  18. newtonsoft动态修改JObject
  19. log4j2动态修改日志级别及拓展性使用
  20. Android:数据持久化(1/2)文件、SharedPreferences

热门文章

  1. acceptorThreadCount
  2. Mercurial
  3. How many ways??---hdu2157(矩阵快速幂)
  4. Spring boot maven 搭建框架
  5. SQL Server批量数据导出导入BCP&amp;Bulk使用
  6. (转)《SSO CAS单点系列》之 15分钟让你了解SSO技术到底是个什么鬼!
  7. 29张截图-全新安装CentOS7.5-超详细!
  8. 使用Ajax向服务器端发送请求
  9. 自定义 Repository 方法
  10. ruby on rails validates