Hi all,

Im getting the following error when i try running the attached applet:

java.security.AccessControlException: access denied (java.net.SocketPermission localhost:8080 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at App$Listen.actionPerformed(App.java:26)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

the applet is loading fine, but when i press the submit button (to connect to servlet), i get the above error.. I think it has something to do witht the fact that my applet is on my local disk and im using localhost8080 url for the servlet..Can someone help me out here please. Thanks

/******** APPLET ********/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;

public class App extends Applet {
  //Initialize the applet
  String printMsg="Message from Servlet..->";
  TextArea txt=new TextArea(10,20);
  Button submit=new Button("Submit");
  Label lbl=new Label("Message from Servlet..->");
  public void init() {
        add(txt);
        add(submit);
        add(lbl);
        submit.addActionListener(new Listen());
   }

   public class Listen implements ActionListener{
     public void actionPerformed(ActionEvent e){
        try{
     class Listen implements ActionListener{
     public void actionPerformed(ActionEvent e){
        try{
        	URL testServlet = new URL(getCodeBase(), "servlet/Serv?Msg=" +URLEncoder.encode(txt.getText()));
         URLConnection servletConnection = testServlet.openConnection();
         BufferedReader inputFromServlet = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
         String msgFromServlet=null;
            while((msgFromServlet=inputFromServlet.readLine())!=null)
               printMsg+=msgFromServlet;
            lbl.setText(printMsg);
            validate();
         }catch(Exception exp){exp.printStackTrace();}
     }
   }
}


/*********** SERVLET **********/

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Serv extends HttpServlet {

  //Initialize global variables
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String param=request.getParameter("Msg");
    PrintWriter out = new PrintWriter (response.getOutputStream());
    out.println("Received msg.."+param);
    out.close();
  }
}

That's a security exception. You don't have permission somewhere. Try compiling the applet as an application instead and see if you still get the error. If you do then you're probably trying something that's not allowed by the OS settings. Otherwise the security exception is being thrown by your browser or applet security settings.

Edited 6 Years Ago by seanbp: n/a

This article has been dead for over six months. Start a new discussion instead.