• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading a file from my web server using an applet

 
Paul McCaffery
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul McCaffery
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

Notes:
  • Error messages are written to the java console.

  • Does it help you?
    Good Luck,
    Avi.
     
    Paul McCaffery
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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!
     
    Avi Abrami
    Ranch Hand
    Posts: 1141
    1
    Java Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Tim Holloway
    Saloon Keeper
    Posts: 18359
    56
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Paul McCaffery:
    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?

    Yes. Unless you sign an applet, you can open network connections to the exact same server that the applet was downloaded from.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic