Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
japplet reads input from file, but not displaying

Posted by erickio (erickio), 19 April 2005
I've been working on a japplet to display the contents of files once the names of their targets have been typed and then a button is clicked. My problem is that I know that each part will work separately (I checked the part that just opens the file and retrieves contents from main after moving it to a new .java file), but when I combine them into the japplet, nothing is being displayed. I was wondering if anyone could help me figure out what the problem is. Thanks.

Also not sure if this is helpful. But the file that I'm opening is on the same machine that the applet and html code are on.

Applet code
<code>
public class go extends JApplet implements ActionListener {

JTextField mytx;
JButton clickme;
JLabel label;
JPanel toppan;
JTextField centertx;
String sourcer=new String();

public void init() {
Container c=getContentPane();

LayoutManager mylm=new FlowLayout();
toppan=new JPanel(mylm);

mytx=new JTextField("enter the dut to traceroute to");
mytx.addActionListener(this);
toppan.add(mytx);

clickme=new JButton("click me");
clickme.addActionListener(this);
toppan.add(clickme);

c.add(toppan, BorderLayout.NORTH);

label=new JLabel("this is the label");
c.add(label, BorderLayout.SOUTH);

centertx=new JTextField();
c.add(centertx, BorderLayout.CENTER);
}

public void start() {
}

public void stop() {
}

public void destroy() {
}

public void paint(Graphics g) {
super.paint(g);
centertx.setText(sourcer);
}

public void actionPerformed(ActionEvent e) {

// if (e.getSource() == mytx) {
// sourcer=mytx.getText();
// }

if (e.getSource() == clickme) {
//sourcer="clickme yeah";

String fh="/homes/interop/ec/temp/thor_" + mytx.getText();
File myfile=new File(fh);

StringBuffer contents=new StringBuffer();
BufferedReader input=null;

try {
input=new BufferedReader(new FileReader(fh));
String line=null;
while ((line= input.readLine()) != null) {
contents.append(line);
contents.append(System.getProperty("line.separator"));
}

}

catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
finally {
try {
if (input != null) {
input.close();
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
sourcer=contents.toString();

}

repaint();
}

}
</code>

html code
<code>
<html>
<applet code="go.class" width=500 height=500>
</applet>
</html>
</code>


Thanks in advance.


Posted by admin (Graham Ellis), 20 April 2005
Applets can usually read data from the system from which the applet was loaded and not from the local machine - this is sometimes known as "sandboxing" and is for security reasons.  

Just imagine that you visited my web site and I send you an applet that generates pretty graphics - but also reads files off you disc and, unknown to you, uploads your confidential information to me.  You would not be pleased.   And so to avoid problems like this (and worse) the restriction is applied.  

I suspect that this has trapped you if it works in individual parts / on an individual machine and in individula parts, but "refuses" when all put together.

Posted by erickio (erickio), 20 April 2005
on 04/20/05 at 06:59:17, Graham Ellis wrote:
Applets can usually read data from the system from which the applet was loaded and not from the local machine - this is sometimes known as "sandboxing" and is for security reasons.  

Just imagine that you visited my web site and I send you an applet that generates pretty graphics - but also reads files off you disc and, unknown to you, uploads your confidential information to me.  You would not be pleased.   And so to avoid problems like this (and worse) the restriction is applied.  

I suspect that this has trapped you if it works in individual parts / on an individual machine and in individula parts, but "refuses" when all put together.


I understand what you're saying. I think i might not have explained the diff parts and why I'm confused.

This program is part of a series of programs.

The first is a perl cgi script that dumps files based on traceroute info into the /homes/interop/ec/temp/ directory.

It then displays a link to where the applet is.

This is the more relevant part. When the applet displays it offers them a few options to input, what device is being tested as well as a button to submit that info. It should be okay in terms of security because it's all done in one .java file, with accesses to read the result files (or should be allowed access at least). I don't know if it's that I'm misunderstanding something which it sounds like. Local machine is the client running applet, and server is where the applet and the result file reads are, right?

It's actually only one program. The reason I moved pieces into another one was to make sure that the part that opens and reads the files even ran by itself when done by command line (which it does). So I don't understand what makes it fail. Since the only input the client is giving is the name of the file to read. and also clicking the button.

Thanks for the reply.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho