Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!aioe.org!.POSTED!not-for-mail From: emf Newsgroups: comp.lang.java.programmer Subject: Re: Applet not running on the web Date: Thu, 10 Jan 2013 07:08:11 -0500 Organization: Aioe.org NNTP Server Lines: 141 Message-ID: References: <50ea1db2$0$284$14726298@news.sunsite.dk> NNTP-Posting-Host: q0ALVNQQ0ipGALYDIb4tnQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:21298 On 2013-01-09 02:01 Lew wrote: > emf wrote: >> Arne Vajhøj wrote: >>> emf wrote: >>>> The webpage is: >>>> httρs://files.nуu.edц/emf202/ρublic/jv/NatalTransits.html >>>> >>>> and you can find the code in >>>> >>>> httρs://files.nуu.edц/emf202/public/jv/transits/NatalTransitsApplet.java >>>> >>>> The applet was working without a problem from the beginning in the >>>> eclipse applet viewer. Then I managed to make it work on browser from my >>>> computer by putting the class and the csv files into a transits folder >>>> (like the package in eclipse) and the html in the higher level >>>> directory. Then I created the same structure in the webserver. The > ... >>> Ooops. >>> >>> #FileReader ephemeris = new FileReader("transits/ephemeris.csv"); >>> >>> applets run client side! >>> >>> The user do not have a transits/ephemeris.csv file and the >>> applet would not have priv to access it anyway. >>> >>> Stuff your class files *and* the CSV file in a jar >>> file and let the Java code retrieve the CSV as a resource! >> >> Unfortunately the suggested solutions does not work. I have both > > What happens when you try it? > > What's the structure of the app inside the JAR? > > Where in the JAR did you put the CSV? > > How is the code attempting to retrieve the CSV? > > I sure hope you aren't calling 'new FileReader()' to get to it! > > Oh! > > 'FileReader ephemeris = new FileReader("transits/ephemeris.csv");' > > That's not how you read it. Use 'getResourceAsStream()' and put a > 'StreamReader' around it. > > See the Javadocs for 'Class'. > >> versions on the server: >> >> httρs://files.nуu.edц/emf202/public/jv/NatalTransitsA.html >> >> uses the jar archive, while >> >> httρs://files.nуu.edц/emf202/public/jv/NatalTransits.html >> >> uses the transits folder. >> >> Both work fine in my browser when running from the local files, but when > > Probably because the JAR version can still see the file system. > >> running through the Internet they both give a >> java.security.AccessControlException, after using > > Probably because you still haven't changed the code to comply with > Arne's suggestion. > > Additional comments: > > - Don't use TAB characters to indent code for public consumption. > - For Christ's sake, man, Javadoc your code! I haven't yet started using the Javadoc eclipse feature. Coming soon. > - 'String textLine = null;' Don't assign values you will never use. This happens when during the program development the compiler complaints that a variable has not been initialized, so you initialize it. In later stages of the development you change the code so the initialization is superfluous - though it doesn't hurt. At still later stage you may realize that it is superfluous, and you remove it. > - 'String textLine = null;' declared at too broad a scope. > - 'catch (Exception e)' is far too broad. Catch the particular exceptions. If I had used catch (Exception e) from the beginning instead of IOException, I would have known what was wrong a couple of days earlier. So, from bitter experience, I learned that it is wise to use Exception, until at a later stage, when everything is working OK, you may return and change it, as an icing on the cake. > - 'String birthday$' Never use '$' in your variable names. Ever. > It's for system-generated stuff only. That was from my good old QBasic days... And I thought it was such a great idea! Pity. Anyway, I replaced $ with S when necessary. > Follow the naming conventions in the Java Coding Conventions. > - 'int[][] planetArray' Generally, variable names should not indicate their > implementation but their purpose. Since I learned about it, I enjoy Refactoring class, method, and variable names. I will change it when I think of an appropriate one. > - 'int[][] planetArray' not the best type. You're storing what are essentially > strings there, as 'int' values. You can invent your own type if 'String' > doesn't suffice. Ok, I made it String array, and the code is actually simpler now. > - 'planet1 = (planet1 - planet2 > 21540) ? ...' Magic numbers are bad. 360° * 60' = 21600'. From 29PI00 to 01AR00 it's 2°, not 358°. I added a comment. > - 'package transits;' Good. As I've said, with the jar I can have everything in the same folder, so if eclipse wants to use packages I do not mind. The new program: https://files.nyu.edu/emf202/public/jv/NatalTransits.html and the code https://files.nyu.edu/emf202/public/jv/NatalTransitsApplet.java I am grateful that you took the time to correct my mistakes and help me effectively in improving my code. Regards, Eustace -- Date Calculator with all-purpose JS code https://files.nyu.edu/emf202/public/js/dateCalculator.html