NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on March 12, 2010, 08:39:04 am



Title: How to write the applet code for embedding in other websites where jar is upload
Post by: lookang on March 12, 2010, 08:39:04 am
Hi Prof,
How to write the applet code for embedding in other websites where jar is uploaded?

for example,
http://lookang.wikispaces.com/

i uploaded the jar file to wikipspaces
http://lookang.wikispaces.com/file/detail/ejs_users_sgeducation_lookang_Momentum1D2010web.jar

the page currently has 2 embed codes

the first one works well, because the codes is modified to read from  http://www.phy.ntnu.edu.tw/ntnujava/ejsuser/14019/ejs_Momentum1D2010web.jar

 
Code:

but now the second embed code i want to experiment and draw the applet codes from http://lookang.wikispaces.com/file/detail/ejs_users_sgeducation_lookang_Momentum1D2010web.jar

i tried
Code:

but i got an error message
Quote
APPLET tag missing CODE parameter.
load: class users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.class not found.
java.lang.ClassNotFoundException: users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.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://lookang.wikispaces.com/ejsuser/14019/users/sgeducation/lookang/Momentum1D2010web_pkg/Momentum1D2010webApplet/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: users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.class

I thought everything is inside the jar, how come cannot find class users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.class ?

what should the embed codes be for different url address of the jar?
thanks!


Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: Fu-Kwun Hwang on March 12, 2010, 10:07:44 am
The jar fie is available from http://lookang.wikispaces.com/file/detail/ejs_users_sgeducation_lookang_Momentum1D2010web.jar
However, the above URL is a web page content which show the download link.


You can find out the actual URL from the above web page:
http://lookang.wikispaces.com/file/view/ejs_users_sgeducation_lookang_Momentum1D2010web.jar/126986537/ejs_users_sgeducation_lookang_Momentum1D2010web.jar
Separate the above URL into path and file part
path=http://lookang.wikispaces.com/file/view/ejs_users_sgeducation_lookang_Momentum1D2010web.jar/126986537/
file=ejs_users_sgeducation_lookang_Momentum1D2010web.jar
Then, the code base and archive tags for applet code should be
Code:
codebase="path" archive="file"
The name and id tags should be unique at the same page (if you have more than one applets , each name and id should be unique).
So the complete applet code to show the applet might be
Code:
<applet archive="ejs_users_sgeducation_lookang_Momentum1D2010web.jar" code="users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.class" codebase="http://lookang.wikispaces.com/file/view/ejs_users_sgeducation_lookang_Momentum1D2010web.jar/126986537/" height="600" id="Momentum1D2010web3151" name="Momentum1D2010web3151" width="900"></applet>

The following is the result of the above code





Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: lookang on March 12, 2010, 11:59:56 am
amazing! You solve the problem. Thanks

I figure you

from browser click on View and Page Source
CTRL-F to find the keyword or browse and CTRL-C the the file and path as you mentioned above.

interesting. I didn't know the the file right-click copy link is different from the actual path and file.

i now can follow your example code and progress on.

Thanks! 


Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: lookang on March 12, 2010, 12:33:04 pm
hmmmmm...i thought i understood the codes but when i tried it on my own forum http://66.7.205.91/~lookangc/index.php?topic=1009.0

from


I thought the file name is correct
applet archive="ejs_users_sgeducation_lookang_Momentum1D2010web.jar"

I thought the path should be this
codebase="http://66.7.205.91/~lookangc/public_html/attachments/"

i tried many different path but seems all wrong
codebase="http://66.7.205.91/~lookangc/home/lookangc/public_html/attachments/"
codebase="http://66.7.205.91/~lookangc/attachments/"
etc it does not seem to work.


the actual attachment is here http://66.7.205.91/~lookangc/index.php?action=dlattach;topic=1009.0;attach=1107

the error message is
Java Plug-in 1.6.0_18
Using JRE version 1.6.0_18-b07 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\temp
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to
----------------------------------------------------


load: class users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.class not found.
java.lang.ClassNotFoundException: users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.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://66.7.205.91/~lookangc/public_html/attachments/users/sgeducation/lookang/Momentum1D2010web_pkg/Momentum1D2010webApplet/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: users.sgeducation.lookang.Momentum1D2010web_pkg.Momentum1D2010webApplet.class

How do i solve this?
Thanks!


Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: Fu-Kwun Hwang on March 12, 2010, 03:08:33 pm
Quote
the actual attachment is here http://66.7.205.91/~lookangc/index.php?action=dlattach;topic=1009.0;attach=1107

1. There is no way to separate the filename and the file path, because the above URL did not contain file name.
You can use archive="the actual attachment is here http://66.7.205.91/~lookangc/index.php?action=dlattach;topic=1009.0;attach=1107" and without codebase in the applet tag to solve the problem.
However, the above URL did not link to the jar file. Because it will be re-direct to login page.
May be you will not see the login page , because browser did the login trick for you.
However, it you logout your forum and try to aceess the above URL again, it will be re-direct to login page.

The same things happened when java/other users try to access the above URL.
That is the reason why java was not able to find the required jar file with the above URL(java should not be able to acces your server because java program can not login)


Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: lookang on March 13, 2010, 08:54:10 am
http://66.7.205.91/~lookangc/index.php?action=dlattach;topic=1009.0;attach=1107

based on the discussions
i tried


i think it work for your forum , am currently login to my forum.
I going to try on my forum. 
Horray!!!!!! it works!!! cool thanks!
U are a great sage!


Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: Fu-Kwun Hwang on March 13, 2010, 09:32:01 am
It will only work for you when you login to your server first.
However, it would not work for other users (in general).
Because other user did not know that they need to login to your server before there access the above page.

I will be re-direct to a login page when I try to access http://66.7.205.91/~lookangc/index.php?action=dlattach;topic=1009.0;attach=1107
You need to provide an URL which is open to public (without login requirement).


Title: Re: How to write the applet code for embedding in other websites where jar is up
Post by: lookang on March 13, 2010, 11:55:04 am
It will only work for you when you login to your server first.
However, it would not work for other users (in general).
Because other user did not know that they need to login to your server before there access the above page.

I will be re-direct to a login page when I try to access http://66.7.205.91/~lookangc/index.php?action=dlattach;topic=1009.0;attach=1107
You need to provide an URL which is open to public (without login requirement).

I used a trick, i login as admin, goto members permission, modify guest permission, check on the box
Attachments
View attachments set to true by selecting the checkbox, Done!!, like a normal applet website now.

i think i will    stick to SMF forum for the time being, i will just post here for community outreach and on my own SMF as a alternate backup!

thanks for your excellent help!


Title: Re: How to write the applet code for embedding in other websites where jar is upload
Post by: Fu-Kwun Hwang on March 13, 2010, 07:43:43 pm
Yes. You got it. You need to make sure anonymous user can access the correct jar file from the provided URL.