Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetching a URL in TextArea within applet

Status
Not open for further replies.

duan

Technical User
May 30, 2001
9
GB
It's a GUI interface in java applet. What I want to do is let user input a URL in a TextArea and program will get this URL to retrieve the content of the indicated web page.

source code is:
--------------------------------------------------
if ( str.equals("Submit data source") )
{ if (source.equals("URL"))
{

String s = text.getText();
System.out.println("URL:" + s);

try{
Source currentURL = new Source( s );
URL curl = new URL(s);
currentURL.ReadinURL(curl);}

catch (MalformedURLException mal) {
text.setText("Bad URL: " + s);
}
---------------------------------------------------

ReadinURL method in Source class is like this:

public void ReadinURL(URL url)
{//read in a URL and retrieve the cotent from it
InputStream is = null;


int i=0;
try
{
// Get InputStream
is = url.openStream();
Reader reader = new InputStreamReader(is);
BufferedReader br = new BufferedReader(reader);

String line = null;
while ((line = br.readLine()) != null)
{
System.out.println("line" + line);
html = line;
i++;
}
}
catch (IOException ioException)
{
System.err.println("Error processing: " + url);
}
finally
{
if (is != null)
{
try
{ is.close();}
catch (IOException ioException) {}
}
}//end of finally
}

But exception throws when execute it:

java.security.AccessControlException:access denied(java.net.SocketPermission resolve)

Please if you want to know how to solve this problem,please email me jane_duan@yahoo.com I'd very appreciate!

Thanks.

duan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top