aspose file tools
The moose likes Applets and the fly likes Logging events in Applet to server using log4j? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Logging events in Applet to server using log4j?" Watch "Logging events in Applet to server using log4j?" New topic

Logging events in Applet to server using log4j?

Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi all,

I want to use log4j for my applet application. I did, but throwing exception while writing log file.

at org.apache.log4j.Logger.getLogger(
at common.VoiceApplet.<init>(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$ Source)
at Source)
Caused by: access denied ( logs\log.txt write)
at Source)
at Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkWrite(Unknown Source)
at<init>(Unknown Source)
at<init>(Unknown Source)
at org.apache.log4j.FileAppender.setFile(
at org.apache.log4j.FileAppender.activateOptions(
at org.apache.log4j.config.PropertySetter.activate(
at org.apache.log4j.config.PropertySetter.setProperties(
at org.apache.log4j.config.PropertySetter.setProperties(
at org.apache.log4j.PropertyConfigurator.parseAppender(
at org.apache.log4j.PropertyConfigurator.parseCategory(
at org.apache.log4j.PropertyConfigurator.configureRootCategory(
at org.apache.log4j.PropertyConfigurator.doConfigure(
at org.apache.log4j.PropertyConfigurator.doConfigure(
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(
at org.apache.log4j.LogManager.<clinit>(
... 11 more
Exception: java.lang.ExceptionInInitializerError

I googaled and got solution

This isn't really a log4j question, because it is because your applet is running in the browser sandbox, and has no permission to create a Socket to any other host other than the host it was launched from.

You'll need to configure the applet to run out of the sandbox; effectively granting it access to connect to hosts other than the web server it was launched from before this will work.

I think you need to write a policy fie for it which grants security permission to the java files,I faced this problem in RMI implementation.

Can any one explain how to implement above solutions


Ritesh Pareek
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42956
Both of the quotes are somewhat misleading. The first, because your logging code doesn't use sockets but files. Access to the local file system is indeed restricted for security reasons, but it's possible to use sockets to connect to the server where the applet was served from WITHOUT leaving the sandbox.

The second, because granting the applet access to the local file system would allow your code to run, but it doesn't help with logging to the server.

So, you need to find a way to transfer the logging information to the server, and have it logged there. The package supports this, in the shape of the SocketAppender (on the client) and SocketNode (on the server) classes.

Implemented this way, it should not be necessary to alter the local security policy, or to sign the applet.
Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi Dittmer,

Thanks for one more valuable reply , actually i made a temporary solution, i just added a space at the bottom of my applet window and start printing log in to that window at run time, i don't have permission to access to server that's why i done it in this way.

Thanks for reply.
I agree. Here's the link:
subject: Logging events in Applet to server using log4j?