开发者

Help passing GET data to a php file in the same location as my Java applet

I have a java applet trying to pass some GET data to a php file in the same directory as my applet. When I start a url connection to the file.php and pass the data, I don't get anything, however when I append the full URL in front of the PHP file, it works.

Here's what I have:

URL sp = new URL ("file.php?data1=" + data1 + "&data2=" + data2 + "&data3=" + data3);
BufferedReader in  = new BufferedReader(new InputStreamReader(sp.openStream()));

But, the data only gets passed if i add my full http://www.website.com/ url in fron开发者_如何学运维t of file.php

EDIT: It works now, with a URL test = new URL(getCodeBase(), "form.php");


Given documents located: - http://www.website.com/docs/applet.html (document base) - http://www.website.com/forms/form.php (target form)

server (http://www.website.com/)

  • docs
    • applet.html
  • forms
    • form.php

An URL to form.php can be created using either of..

// relative URL
URL relative = new URL(getDocumentBase(), "../forms/form.php");
// absolute URL
URL absolute = new URL(getDocumentBase(), "/forms/form.php");


Have you tried Applet's getCodeBase?

As per document

public URL getCodeBase()
   Gets the base URL. This is the URL of the directory which contains this applet.
  Returns:
    the base URL of the directory which contains this applet.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜