随笔 - 367  文章 - 0  评论 - 20  阅读 - 63万 

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

 

jsp页面:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<%@ 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页面:

 

1
2
3
4
5
6
7
<?php
 
$username = $_REQUEST['name'];
 
echo($username);
 
?>

 

posted on   巨象  阅读(1945)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示