用php模拟post将一个数组传递到到xxx.jsp,jsp页面能直接获取数组值。
如:php数组数据为:name:abc,pwd:123,email:xxx@xxx.com。
php打包成数组,$arr = arry($name,$pwd,$email);
如何将$arr 数组传递给xxx.jsp?
是传递数组,而不将数组变成字符串 传递。

解决方案 »

  1.   

    php传递给jsp ??是html表单吧, 都是用post提交才能传数组, 不明白你想表达什么意思$arr = arry($name,$pwd,$email);  ??
      

  2.   

    少打了个a。
    $arr = array($name,$pwd,$email);
    将php的$arr数组post给jsp。
      

  3.   

    可以直接用表单传递,不需要数组,再目的页面再用post方法获取就可以了
      

  4.   

    可以直接用PHP模拟POST数据,就像实际提交表单一样。不过这个功能可能需要你配置一下PHP.INI,需要的模块默认不支持,很多虚拟主机空间也都不支持的
      

  5.   

    JSP还可以直接接收并读取PHP的数组?没听过,不过,我觉得既然是用HTML的表单来提交了,那就直接用HTML的方式来传参数吧
    <input name='name' value='abc' />
    这样不管在JSP、PHP、还是ASP都可以解析。
      

  6.   

    直接使用 socket 就可以了,模拟HTTP数据包至于数组在数据包里是什么样的,你用抓包工具看下就可以了我先给你个 socket 的class<?phpclass socket
    {
    var $fsk;
    public function connect($host, $port)
    {
    $fsk = @fsockopen($host, $port, $eno, $estr, 10);
    if (!$fsk)
    {
    return false;
    }
    $this->fsk = $fsk;
    return true;
    }
    public function send($content)
    {
    fputs($this->fsk, $content);
    return true;
    }
    public function receive()
    {
    $fsk = $this->fsk;
    // header
    $buffer = '';
    while ( !feof($fsk) )
    {
    $line = trim(fgets($fsk, 256));
    if ('' == $line)
    {
    break;
    }
    $buffer .= $line."\n";
    }
    $header = $buffer; // body
    $buffer = '';
    if (!$fsk || @feof($fsk))
    {
    $buffer = 'null';
    }
    else
    {
    while ( !feof($fsk) )
    {
    $buffer .= fgets($fsk, 256);
    }
    }
    $body = $buffer; $this->fsk = $fsk;
    $return = array(
    'header' => $header,
    'body' => $body
    );
    return $return;
    }
    public function close()
    {
    fclose($this->fsk);
    }
    }?>用法
    <?php// HTTP数据包内容
    $post = <<<package
    POST /post/ HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN
    Referer: http://www.uuland.cn/
    Content-Type: application/x-www-form-urlencoded
    Content-Length: xx
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
    Host: 127.0.0.1
    Connection: Close
    Cache-Control: no-cache
    Cookie: PHPSSIONID=abcZBkWhZqweFfs-s-kvsdata of post
    package;include 'socket.php';
    $sck = new socket();
    $sck->connect('www.uuland.cn', 80);
    $sck->send($post);
    $response = $sck->receive();
    $sck->close();
    unset($sck);
    print_r($response);
    ?>
      

  7.   

    不明白,你就两个字段,你也搞成数组,POST 参数带过去不就可以了。搞那么复杂
      

  8.   

    用fsockopen,先用html和form提交,用httpwatch一类的软件,捕获通讯内容,改改下面的内容,把$out改成捕获到的header信息就行了.$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    } else {
        $out = "捕获到的header信息";    fwrite($fp, $out);
        while (!feof($fp)) {
            echo fgets($fp, 128);
        }
        fclose($fp);
    }