?
Solved

Java Applet that pull URL data

Posted on 2005-03-16
5
Medium Priority
?
286 Views
Last Modified: 2013-11-23
I want to pull up a web page on my site containing the java applet below that will pull a piece of data from another internet site and display it thur my applet.

but I get "access denied (java.net.SocketPermission www...some.....  connect,resolve)

I tested it using the appletviewer with a local profile and it worked fine (ppletviewer -J-Djava.security.policy=polfile URLReader1.htm )

Do I add logic to the applet to similuate the profile, do I put a profile file on mysite and/or how do i reference it. etc?

Remember my applet on my site page is pulling the url from another site.


import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.io.*;
public class URLReader1 extends JApplet{
   String message;
   public void init() {
       try
       {
        URL httpurl = new URL("http://www.---someurl---.com");
        BufferedReader in = new BufferedReader(new InputStreamReader(httpurl.openStream()));

        StringBuffer result = new StringBuffer();
        StringBuffer dest = new StringBuffer();
        String tempxml;
        String startxml;
        String endxml;

        String inputLine;

        int     c;
        char    x;
        while ((c = in.read()) != -1)
           {
             x  = (char) c;
             //System.out.println(x);
             dest.append(x);
           }

        int isque = dest.toString().indexOf("</td>");
        isque=isque+01;
        tempxml = dest.toString();
        startxml = tempxml.substring(isque,isque+100);

        message=startxml;

        isque = startxml.toString().indexOf("<b>");
        isque=isque+03;
        tempxml = startxml.toString();
        endxml = tempxml.substring(isque,isque+5);

        in.close();
         }
        catch (Exception e)
           {
                  message=e.getMessage();
           }
    }
 public void paint(Graphics artist)
        {
          artist.drawString(message,20,330);
        }
}

<html>
<body>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase= "http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,2,0"
codetype="application/java" standby="Loading..."
height="600" width="600">
<param name="code" value="URLReader1.class">
</object>
</p>
</body>
</html>
0
Comment
Question by:MrBoiledCrawfish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13556677
You'll need to sign your applet if you want to distribute it. If it's just for you use you can edit the policy file. Either way, you'll need to add the permission to allow it to connect to another host
0
 
LVL 5

Expert Comment

by:steve_bagnall
ID: 13556701
Hi MrBoiledCrawfish,

You can't access one domain from another, for security reasons.  I think this will be your problem.

Cheers,
Steve
0
 

Author Comment

by:MrBoiledCrawfish
ID: 13556749
So how do I get the applet on mypage on mysite to reference the policy file or is that a webserver setup (IIS)?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13556877
No, the applet runs on the client machine - it has nothing to do with the site, apart from originating there. The sandbox is on the client machine, as is the policy file. If you have access to it, you can alter it. Otherwise you must sign the applet.

http://www.mindprod.com/jgloss/signedapplets.html
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 13560012
your users would need to update their policy file.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question