Applet referencing to localhost gets blocked if html is on shared drive - java

I have an html file with applet code like
<applet code="myapplet.class" archive="http://localhost:8080/myapplets.jar"width="350" height="350"></applet>
The applet loads fine if the html file is local to the machine but if that html file is on shared drive (windows) and if html file opened ( so that the address in the address bar is
\X.X.X.X\testhtml\myapplethost.html ) then
While applet is trying to load , this exception is thrown
java.lang.SecurityException: Permission denied: http://localhost:8080/myapplets.jar
I have added both the
http://localhost:8080 and file:\\X.X.X.X\testhtml
to the exception list. Have lowered the security to the lowest possible (i.e Medium) in java control panel (JRE 1.7 upate 67) but this applet keeps getting blocked. Is there any settign that can help here to allow the access to applet from the shared location? Thanks

The archive parameter of the applet can only reference archives (e.g. jar files) from the same source the applet was started. Here is the quote from the official documentation:
For security reasons, the applet's class loader can read only from the same codebase from which the applet was started. This means that archives in archiveList must be in the same directory as, or in a subdirectory of, the codebase.
If you load the HTML page from a shared drive, the archive attribute of the applet tag in the HTML file should not point to http://localhost:8080/myapplets.jar. Most likely this is just a mistake (you forgot to change it or you forgot to use relative URL).
Just change the archive attribute to a relative URL and it will work. Something like this:
<applet code="myapplet.class" archive="myapplets.jar" width="350" height="350">
</applet>
Absoulte URLs are always a bad idea and this is especially true for applet archives.

Used shared drive path (like Z: instead of \server ) and it works.

Related

Can an embedded Java Applet be hosted on Git-Pages?

I want to embed a java applet (stored in a git repository) in the accompanying github-pages page. Is this possible?
Yes.
Although GitHub pages can be generated through a simple markdown interface, any files in your branch will be served as part of your gh-pages-site.
This means you can host client side scripts like Java-Applets or JS on your GitHub Pages site.
To host a java applet:
Create a jar file for your Applet.
Place the .jar file into the root of your gh-pages branch.
Embed the applet in one of your html pages using your prefered method like this, or maybe this:
*Assuming foo.jar and Bar.class are your file and applet-class*
<embed
id="SomeName"
type="application/x-java-applet;version=1.6"
width="999" height="999"
archive="foo.jar"
code="Bar.class"
pluginspage="http://java.com/download/"
myParam="YourParams" />
Commit/Push the changes and wait (sometimes gh-pages are not updated immediately).

Why is there a file permission error?

I am getting a file permmission error when I use my Java applet on my website.
The error is:
access denied ("java.io.FilePermision""image.png""read")
An applet operates in a restricted environment (known as a security sandbox) and,unless it is signed, can only load resources from the same location from where it was loaded. The images can be included in the applet jar file. To access these, you could use
Image image = ImageIO.read(MyApplet.class.getResourceAsStream("/images/image.png"));
Applets are by default denied from accessing the client's file I/O. You need to sign your applet or edit the policy files.
You can check How Can An Applet Read Files On The Local File System

why doesn't the server pick up the path i give it in the image tag?

I am using glassfish. on a jsp page when i write :
<img src="/home/non-admin/project users/pic.jpg"/>
the IDE highlights the line with an error saying this is a bad value. But when i give the path( to the same image) from the directory inside the project it picks it up and displays the image. Like project/images/pic.jpg Why doesn't it pick up just any path from my system. How can i do this ?
It can't pick up any path of your system (Imagine some one is reading your system's file by just accessing path in their browser :) ), You need to write a Servlet which will read that file from your system and write to output in response
The problem is because it is based on the path to the base of the webpage, which is usually something like /var/www/htdocs To allow something in a homedirectory you can create a link to that directory from within the web directory something like ln -s /home/non-admin/project\ users/ /var/www/htdocs/userdata then use <img src="/userdata/pic.jpg"/>. Also you need to set the permissions on the directory/file to allow the www user to read it.

JApplet works in applet viewer, not in HTML page

This topic has been covered in one form or another but none of the other threads have been able to help. My issue is very similar to this post, I am making a JUNG graph with added functionality, but none of the solutions helped:
JApplet fails to run in HTML page
I had a Java application that I converted to a JApplet. The JApplet works fine in the applet viewer in Eclipse but will not work when I try to open it in a webpage (I have tried IE, FireFox, and Chrome). I have my HTML page and archive folder both in the same directory. When I load the HTML page it just brings up nothing.
Here is my html code:
<html>
<title>Applet</title>
<head>
</head>
<body>
<applet code="prerna.blueprint.main.BPTester.class"
archive="applet1.jar"
width="800" height="800">
</applet>
</body>
</html>
When I try to have code="BPTester.class" it gives java.lang.ClassNotFoundException: BPTester.class but when I use code="prerna.blueprint.main.BPTester.class" it gives me no errors just nothing happens. (prerna/blueprint/main/BPTester.class is the file path in my src folder). I exported my Java project as a runnable jar file, is this correct? I created a simple JApplet that worked fine when I did all the same steps but it won't work for BPTester.class.
If I need to post my BPTester.class code I can.
I don't understand why I can't view the JApplet in a webpage, any help is greatly appreciated.
What ended up working for me was adding every single jar I used in the japplet to the HTML archive tag then had to sign every jar. I then had an issue with accessing my database within the applet1.jar so I just put an absolute path for its location.
java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
The applet needs to be digitally signed (by you) and trusted (by the end user, when prompted) before it can obtain such information. Given this applet is being deployed using a traditional applet element (i.e. not using web start), all jars need to be signed.
You need to sign every jar. You can sign all the jars with the jarsigner utility. Example:
jarsigner.exe "nameofthejar.jar" "alias"
Remove .class from the end. You either use a file path with slashes and .class at the end or you only use periods and no .class at the end.
Try turning on tracing in the java control panel. It will then produce a log file in the following path that may help: %USERPROFILE%\AppData\LocalLow\sun\java\Deployment\log

My Applet will not run in a browser

Can anyone help me out. I've written a program that controls the heating system in an imaginery house, an applet actually. it runs fine in netbeans but i cant get it to run as an applet in a browser, can anyone help me out please, I linked to a zip folder of all my code...
http://dl.dropbox.com/u/47863/Heating%20System.zip
http://alcaeos.com/applet/classes/MyHomeHeating.class -> 404.
Or to put that another way.
The applet element is telling the JRE to look for the class at the URL mentioned above.
The class is not at that location. (Neither is it in the same directory as the HTML.)
Where is the class file?
BTW: Typical bloody Netbeans generated code (/HTML). When what it generates is not invalid, it is redundant.
code="MyHomeHeating.class" The code attribute should not include .class.
<HR WIDTH="100%"> An HR element normally spans the entire width of the page.
You need to compile your applet into .class files (not .java files like you have in the ZIP; those are source code) and embed it into an HTML page. You can use the tag in HTML to do these; read more here: http://www.echoecho.com/applets01.htm

Categories

Resources