Forums Register Login

Where should I put the applet?

+Pie Number of slices to send: Send
I have a Graph.java which extends JApplet, and import a java_c.Caller.java which will call a dll in my pc.
Make it clear:
Graph.java extends JApplet,and calls Caller.java
Caller.java calls a dll in my pc.

I want to put them in the Tomcat\webapps\myapp, how shoul I do?
Thanks!!!
+Pie Number of slices to send: Send
You'd put the class files along with the HTML file that contains the applet tag into ...\myapp. I'm not sure where the DLL needs to go on a Windows machine, probably into a directory that's part of PATH.

In any case, you need to allow the applet to use native libraries. The two methods for doing that are described here.
+Pie Number of slices to send: Send
 

Originally posted by Ulf Dittmer:
You'd put the class files along with the HTML file that contains the applet tag into ...\myapp. I'm not sure where the DLL needs to go on a Windows machine, probably into a directory that's part of PATH.

In any case, you need to allow the applet to use native libraries. The two methods for doing that are described here.



Thanks!!But I think the dll file is on my pc, so is in the host, why should I sign the applet.In fact my applet can run on the appletviewer and cannot on the ie or firefox?
+Pie Number of slices to send: Send
Because applets have security restrictions in what they are allowed to do. Accessing native libraries is one of the things they can't do. Appletviewer does not generally enforce these restrictions, but browsers do.
+Pie Number of slices to send: Send
 

Originally posted by Ulf Dittmer:
Because applets have security restrictions in what they are allowed to do. Accessing native libraries is one of the things they can't do. Appletviewer does not generally enforce these restrictions, but browsers do.



Thank for your answer!!!
+Pie Number of slices to send: Send
Another question:
I have resolve the problem dll.I make a jar file including the applet、the Caller(call the dll)and 3 images.The applet should read the images,one is the background, others are button's icons.But why in the browser,the images can't be read?
My step:
1、Make the applet、Caller.java(it's in the java_c package),the images together into applet.jar.
2、Ues the commands:
keytool -genkey -keystore kidd.store -alias kidd
keytool -export -keystore kidd.store -alias kidd -file kiddr.cert
jarsigner -keystore kidd.store applet.jar kidd
3、Create a applet.policy file,with the following content:
keystore "file:E: /javacode/kidd.store", "JKS";
  grant signedBy "kidd"
  { permission java.io.FilePermission }
4、add a line in the ${java.home}/jre/lib/security/java.security:
policy.url.3=file:E: /javacode/applet.policy
Now I can run applet in the browser,but it still can't show the 3 images,why?


One more question:
I want to move the applet.jar in the ${Tomcat.home}/webapps/myapp, I think it mustnot under the ../myapp/WEB-INF, because the applet will be downloaded.But the applet.jar has included the java_c package(Caller.java in it),I want to make the java_c package move from applet.jar to the ../WEB-INF/classes. How can I do?Can the applet in the jar call a class in the WEB-INF/classes?How should I change my code?

Really Thanks!!!
+Pie Number of slices to send: Send
If the images are inside of the jar file, then the browser can't access them - only the applet can read them. If you want to use them in HTML as well, then you need to keep them outside of the jar file.

Applet classes can't be anywhere inside of WEB-INF, because that directory is not publicly accessible.
+Pie Number of slices to send: Send
 

Originally posted by Ulf Dittmer:
If the images are inside of the jar file, then the browser can't access them - only the applet can read them. If you want to use them in HTML as well, then you need to keep them outside of the jar file.

Applet classes can't be anywhere inside of WEB-INF, because that directory is not publicly accessible.



Yes, thanks for your reply.But the first question is "I put the images in the jar, I want them to be read by applet and be showed. One is applet' backgroud ,others are button's Icon. So I think in the browser ,them should be read by applet not html. But in fact, them didn't appear, on the other hand them appeared in the AppletViewer. So I'm puzzled "
+Pie Number of slices to send: Send
I see - by "in the browser" I thought you meant as opposed to "in the applet". But you meant as opposed to "in appletviewer".

What code are you using to access the images? Are there any exceptions?
+Pie Number of slices to send: Send
 

Originally posted by Ulf Dittmer:
I see - by "in the browser" I thought you meant as opposed to "in the applet". But you meant as opposed to "in appletviewer".

What code are you using to access the images? Are there any exceptions?



I'll make my questions clearer next time.
The code to read the backgroud image is


The code of the buttons is:


When the applet is running in FireFox, the console print the exception is:

There aren't any exceptions of the buttons' images. But all the 3 images didn't appear.Please tell me why?Thanks!
+Pie Number of slices to send: Send
 

File f = new File("main.jpg");
img = ImageIO.read(f);



This only works for images in the local file system, not for images that are in the applet jar file, or in the same web directory. Resources in the jar file can be accessed as described here. Files in the web directory can be accessed through HTTP with the HttpUrlConnection class.

As to the image icons, are the images on the top level of the jar file, i.e. not in a directory?
[ January 10, 2007: Message edited by: Ulf Dittmer ]
+Pie Number of slices to send: Send
Thanks !
Following your reply, I made the backgroud image shown in the Firefox.

The two Icons are on the top level of the jar file.What can I do with them?
+Pie Number of slices to send: Send
Here is some code that pulls an image out of a jar file for use as a label:


[ January 10, 2007: Message edited by: Ulf Dittmer ]
+Pie Number of slices to send: Send

You are a nice man!!!Really really thank you!!!
So I left, I came home, and I ate some pie. And then I read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1311 times.
Similar Threads
Java and activeX ?
JNI to DLL architecture
Sending direct keys in J2ME
javascript call from instantiated class which extends JApplet
Calling Java Swing application in JSP Page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:40:05.