Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java post请求返回200,但网页不返回';不变_Java_Php_Json - Fatal编程技术网

Java post请求返回200,但网页不返回';不变

Java post请求返回200,但网页不返回';不变,java,php,json,Java,Php,Json,我有一个Java中的JSON对象(使用Eclipse),我想将它发送到Web服务器,从JSON格式解码并显示在页面上 <?php require("config.php"); $string=$_POST['json']; $decoded = json_decode($string); mysqli_query($con, "Insert into champion VALUES('', '$decoded')"); ?> <!DOCTYPE html> <htm

我有一个Java中的JSON对象(使用Eclipse),我想将它发送到Web服务器,从JSON格式解码并显示在页面上

<?php
require("config.php");
$string=$_POST['json'];
$decoded = json_decode($string);
mysqli_query($con, "Insert into champion VALUES('', '$decoded')");
?>
<!DOCTYPE html>
<html>
<body>
<h1> hello</h1>
<?php
$sql=mysqli_query($con, "Select * from champion");
while($row=mysqli_fetch_assoc($sql)){
    $text=$row['text'];
    echo $text;
}
?>
</body>
</html>
我试图发送JSON对象并返回响应代码,它给了我200,但当我转到网页并刷新时,它没有显示任何内容,就好像它从未收到任何内容一样

我试着看了看类似的问题,但是我相信我遗漏了什么或者我误解了什么

以下是我的Java代码: (我的json对象“obj”已填充,但我没有在下面包含创建和填充它的代码)

这是我的php文件:

<?php
$string=$_POST['json'];
$decoded = json_decode($string);
echo $decoded;
?>
<!DOCTYPE html>
<html>
<body>
<h1> hello</h1>
</body>
</html>

你好
编辑:我创建了一个MySQL数据库来存储来自Java的json字符串,下面是php文件的更新版本,通过它我试图存储来自Java脚本的json字符串并访问它以在页面上显示它

<?php
require("config.php");
$string=$_POST['json'];
$decoded = json_decode($string);
mysqli_query($con, "Insert into champion VALUES('', '$decoded')");
?>
<!DOCTYPE html>
<html>
<body>
<h1> hello</h1>
<?php
$sql=mysqli_query($con, "Select * from champion");
while($row=mysqli_fetch_assoc($sql)){
    $text=$row['text'];
    echo $text;
}
?>
</body>
</html>


您使用的是两个不同的客户端,一个是Java应用程序,另一个是浏览器。您错误地认为客户端1中的更改将反映在客户端2中。java应用程序收到对其请求的响应,web应用程序收到对其请求的响应,但这是两个不同的请求和两个不同的响应?是否将java代码用作嵌入html文件中的小程序?或者?取决于你想要实现什么。好吧,下面是我想要实现的:我用java创建了一个web scraster,它可以从网页中获取信息,并将其存储在json对象中。从那里,我想将json对象发送到一个php文件,在那里我可以从json对象获取信息并将其显示到浏览器,这样每当我访问该php文件时,它都会从java脚本获取信息并将其显示。您必须将其存储在php端的某个位置,无论是内存、文件还是数据库中。更容易的方法是:1)在PHP中实现web抓取逻辑;或者2)还可以用Java(JSP、servlet等)实现表示/web部件