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() {
        submit.addActionListener(new Listen());

   public class Listen implements ActionListener{
     public void actionPerformed(ActionEvent e){
     class Listen implements ActionListener{
     public void actionPerformed(ActionEvent e){
        	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;
         }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 {

  //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);
6 Years
Discussion Span
Last Post by seanbp

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 by seanbp: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.