FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP inside HTML tags?





Neilos
Can i use PHP varables inside a HTML tag like this?

Code:
<applet code=<?php echo $link; ?>.class name=<?php echo $link; ?> archive=<?php echo $link; ?>.jar width=300 height=300>
   <param name="bgcolor" value="ffffff">
   <param name="fontcolor" value="000000">
   Your browser is not Java enabled.
</applet>


because it won't load the applet Sad

EDIT!
I just looked at the source code produced in Mozilla Here is the HTML...

Code:
<html>
<head></head>
<body>


<h2>You chose to play:</h2>
Hello World<br />
<applet code=HelloWorldApp.class name=HelloWorldApp archive=HelloWorldApp.jar width=300 height=300>
   <param name="bgcolor" value="ffffff">
   <param name="fontcolor" value="000000">
   Your browser is not Java enabled.
</applet>

<br />
Click to return to <a href="java.html">Java Applets</a>.




</body>
</html>


The variables seem to work fine Confused

Here is my PHP code...

Code:
<html>
<head></head>
<body>

<?php
// get form selection
$whichGame = $_GET['whichGame'];
// check value and select appropriate item
if ($whichGame == 1) {
    $game = 'Hello World';
    $link = 'HelloWorldApp';
    }
elseif ($whichGame == 2) {
    $game = 'Game 2';
    $link = 'Game2';
    }
elseif ($whichGame == 3) {
    $game = 'Game 3';
    $link = 'Game3';
    }
else {
    $game = 'Game 4';
    $link = 'Game4';
}
?>

<h2>You chose to play:</h2>
<?php echo $game; ?>
<br />
<applet code=<?php echo $link; ?>.class name=<?php echo $link; ?> archive=<?php echo $link; ?>.jar width=300 height=300>
   <param name="bgcolor" value="ffffff">
   <param name="fontcolor" value="000000">
   Your browser is not Java enabled.
</applet>
<br />
Click to return to <a href="java.html">Java Applets</a>.



</body>
</html>


I have the HTML page and the HelloWorldApp.class in the same directory. It might not be a PHP problem, i dunno?!?

Can anyone see why the applet won't work?

The error message in the applet says it cannot find HelloWorldApp.class

Thanks

Neilos
sonam
Everything is looking good. Did you try applet in some other browser then Mozilla? Also, you can try to put double quotes around names.

Code:
<applet code="HelloWorldApp.class" ...


Sonam
Neilos
I tried with double quotes already and it produced the same problem.

Maybe I'll find an open source java.class file to try instead of my Hello world one... I'll report any progress

Neilos
Stubru Freak
Everything seems to look fine, double check if the .class and .jar files are in the same directory (or the <base> directory of your file).
Using PHP doesn't make any difference: the PHP is replaced with the appropriate text before the browser even sees it.
Neilos
The HTML files and the .class files are in the same directory.

The following is the error report from the applet:

Code:
load: class HelloWorldApp.class not found.
java.lang.ClassNotFoundException: HelloWorldApp.class
   at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://www.webtest.frihost.org/HelloWorldApp/class.class
   at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
   at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
   at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   ... 7 more
Exception: java.lang.ClassNotFoundException: HelloWorldApp.class


One line in particular looks strange to me:

Code:
failed:http://www.webtest.frihost.org/HelloWorldApp/class.class


I would assume that the path would need to look lie this:

http://www.webtest.frihost.org/HelloWorldApp.class

Sorry this seems to have migrated from a PHP problem to a HTML/Java problem. Shall I create a new post in the appropriate forum?

Neilos
rvec
Neilos wrote:
Sorry this seems to have migrated from a PHP problem to a HTML/Java problem. Shall I create a new post in the appropriate forum?
Neilos

moved Smile
Neilos
I tried lots of different things all with the same results.

I wasn't actually using a .jar file so I removed this part and also removed the 'name' element too. Here is the HTML that my browser sees after the server parses the PHP code and spews this at me!...

Code:
<html>
<head></head>
<body>


<h2>You chose to play:</h2>
Hello World<br />
<applet code="helloworld.class" width=300 height=300>
   <param name="bgcolor" value="ffffff">
   <param name="fontcolor" value="000000">
   Your browser is not Java enabled.
</applet>
<br />
Click to return to <a href="java.html">Java Applets</a>.
<br />



</body>
</html>


It should work!!! Surely! I think it might be a server issue or a JRE issue?!?!?! Anyone?

Neilos
Neilos
I figured it out.

I had compiled an application and I was trying to run it as an applet. My original HelloWorldApp.class looked like...
Code:

class HelloWorldApp {
  public static void main(String[] args){
    System.out.println("Hello World!");
  }
}

Which worked fine when viewed from the command prompt (which led me to assume that the java code was fine).

Needless to say it didn't work in an applet. I spent some time in Sun Microsystems' tutorials and I came up with this code...
Code:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;

public class HelloWorldApp extends Applet{

  String text = "Hello World!";

  public void init() {
        text = "Hello World!";
        setBackground(Color.cyan);
  }
  public void start() {
        System.out.println("starting...");
  }
  public void stop() {
        System.out.println("stopping...");
  }
  public void destroy() {
        System.out.println("preparing to unload...");
  }
  public void paint(Graphics g){
        System.out.println("Paint");
        g.setColor(Color.blue);
        g.drawRect(0, 0,
                   getSize().width -1,
                   getSize().height -1);
        g.setColor(Color.red);
        g.drawString(text, 15, 25);
  }
}

Which works fine.

I hope this helps clear this matter up for some people cos it had me stumped for ages and no one could find an answer.

I still do not understand it completely so if someone understands this a bit more in depth could you please elaborate on my description and explain it better?

Many thanks.

Neilos
Related topics
PHP Toturail
Using Key Words
Difference between PHP and HTML docs
php/HTML pages question
neep help making email form that accepts html tags
Need help integrating html code into php
new to php: can I use php INSIDE html?
How to change extension php to html but the php script still
php html tags
Help with php and java script
The best php and html editor?
Parsing PHP in HTML
PHP inside Javascript
Common IDE Platform for PHP, CSS, HTML and Specially JQuery
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.