right i have messed about for ages trying to get somewhere and getting nowhere! I have an applet and can't get it to simply read a simple .txt file and print it in my applet. i have the url and i am trying to read the url using InputStreamReaders and BufferedReaders. The code works outside the applet what do i need to do to get it to work? HELP anyone please
This is because a web server is not a file server. So the only way you can get a file from a web server is to request it via URL with the web server being set up to return the desired file for that URL. Tbe best wayfor an applet request a file over HTTP is via the HttpURLRequest HTTP tunneling class. Even if you've done that, however, you can't print it in an applet unless you've signed the applet. Unsigned applets are forbidden the ability to print by the standard "sandbox" rules. That might seem strange, but some Bad Things have been done to peoples' computers/networks via malicious print requests, so the sandbox requires that the applet prove that it comes from a trustworthy source is is trusted to do the right thing.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
posted 17 years ago
how do you sign an applet then? I have accessed the file using a the URL class
Like this then i use the g.drawString method to paint it but can't for some reason?
Hi Paul, The below code was tested in the following environment: Apache Web Server 1.3.12 on SUN [sparc] Solaris 7 Micro$oft Internet Explorer 6.0 on Windows XP with Java 1.4.1_02 plug-in Here is the code:
Error messages are written to the java console.
Does it help you? Good Luck, Avi.
posted 17 years ago
Whoever you are and wherever you come form Avi I THINK I LOVE YOU!!! cannot see the difference between my code and yours but yours works so who cares. May have been something to do with calling the applet.getCodeBase() and only being able to refer to the same URL that the applet comes from? but like i said who cares YOU ARE A LEGEND! AND LONG MAY YOU CONTINUE! i have been trying to get that to work for about a week. thanks again!
Paul, Your very welcome. It was my pleasure, I assure you. From the code you posted, I think your problem was that you were using "DataInputStream" rather than "BufferedReader", and "URLConnection" when the "URL" class is sufficient. Good Luck, Avi. P.S. If you really want to know, I am a software engineer from Israel.