Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default Reading a file from Applet (BufferedReader)

    The code snippet below presents an applet that reads an file and displays its contents on the console of the server.

    Java Code:
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    public class MyApplet extends Applet {
      public void init() {
        readFile("mydatafile.txt");   
      }
      public void readFile(String f) {
        try {
          String aLine = "";
          URL source = new URL(getCodeBase(), f);
          BufferedReader br = 
            new BufferedReader
              (new InputStreamReader(source.openStream()));
          while(null != (aLine = br.readLine())) {
             System.out.println(aLine);
          }
          br.close();
          }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
    }

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default persist return from applet on server

    This is too close to where I am at on my primary project, I have to avail myself of potential help here. After long - slow drudgery in beginner issues, I was recently writing servlet code and JSP -> I figured the jsp could talk to the servlet reasonably well. I reasoned that an applet could be an effective defense barrier at which "At least the respondent is thinking..." could be used to reduce the authentication workload to either authorized access or intrusion attempts that were actually worth logging and trapping. After finding the get call that allows reading of the responses from the client ( browser ) using forms and url's, ... I just sorta relaxed and started helping others hoping to gain enough knowledge along the way to get an applet to talk to a Servlet / JSP combination. I had pretty well saturated my available mind loading.

    Several questions if I may:

    Where is getCodeBase(); a member of base class Applet?
    We open an InputStreamReader, but where are we? -> on the server or on the client? It looks like full Duplex has been replaced with a Dimensionless communicatons protocol where reads and write()'s ....? I see that we are in an Applet, which run client side .... I thought.

    These may sound beginerish coming from someone who can do Threads, but this is actually what I see when I look at the code. I could do a lot with this code if I can get this <- || -> || <- || coming or going figured out. Assume I am trying to get the Applet to send some Base-64 encoded raw to the server so that only verbally transferred knowledge about the Applet and it's behaviour allow an otherwise unannounced respondent to request the actual authentication protocol.

    That will be hardcoded in the Servlet.

Similar Threads

  1. Applet - reading text files packed into JAR file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:15 AM
  2. Reading file contents (BufferedReader)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-07-2008, 09:00 AM
  3. Reading int values using BufferedReader
    By Java Tip in forum Java Tip
    Replies: 2
    Last Post: 01-24-2008, 07:26 PM
  4. Reading text from a URL using BufferedReader
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •