Hugo,
Instead of hardcoding the name of the server in your applet class, you
should use the following code from Marty Hall's book, "Core Servlets and
Java Server Pages" so that the code is not server-dependent. Perhaps it
will also fix your security exception.
URL currentPage = getCodeBase();
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
int port = currentPage.getPort();
String urlSuffix = "/servlet/yourServletName";
URL dataURL = new URL(protocol, host,port,urlSuffix);
URLConnection con = dataURL.openConnection();
-Richard
At 11:55 AM 9/21/01 +0100, you wrote:
>Richard,
>
>ok! i'm gonna try to explain
>
> This is the code where it gives the error:
>public Object getFromServlet(String opcao, String
>am){
>
> Object obj = null;
>
> try{
> URL url = new
> URL("http://phc:8000/main?"+URLEncoder.encode("opcao")+
>
>"="+URLEncoder.encode(opcao)+"&"+URLEncoder.encode("param")+
>
>"="+URLEncoder.encode(param));
> URLConnection con = url.openConnection();
> con.setDoOutput( true );
> con.setDoInput( true );
> con.setUseCaches( false );
> con.setDefaultUseCaches(false);
>
> InputStream in = con.getInputStream(); //THE ERROR OCCURS
> HERE
> ObjectInputStream objStream;
> objStream = new ObjectInputStream(in);
> obj = (Object)objStream.readObject();
> objStream.close();
> in.close();
>
> }catch(IOException o){o.printStackTrace();}
> catch(ClassNotFoundException c){c.printStackTrace();}
>
> return obj;
> }
>
>Has you can see, i think i'm connecting to right url... (like i said i
>think...)
>
>Just a detail this code is not exactly in the applet class file. I'm going
>to explain... My applet is kind of big, it has a lot of stuff so i've
>created a new class which extends JPanel, and put it as an attribute of my
>applet class. May this be a problem?
>
>
>Thanks for your help.
>
> Hugo Malheiro
>-----Original Message-----
>From: A mailing list for discussion about Sun Microsystem's Java Servlet
>API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
>Richard Yee
>Sent: quinta-feira, 20 de Setembro de 2001 19:22
>To: [EMAIL PROTECTED]
>Subject: Re: java.net.ConnectException in applet connection to servlet
>
>
>Hugo,
>Can you describe what your applet is doing again? It still sounds like it
>is trying to make a HttpURLConnection to a server that is different from
>where the applet was downloaded from. Doing this is a security exception
>and changing the permissions is not going to help.
>
>-Richard
>
>
>At 06:54 PM 9/20/01 +0100, you wrote:
> >You were right, about the name server. The problem was that i was using an
> >older version of my file where i've already have changed the name of the
> >server.
> >
> >However the problem persists in another way. In localhost it gives no error
> >but when i run my application in another computer it gives me now another
> >error.
> >
> >Exception occurred during event dispatching:
> >java.security.AccessControlException: access denied
> >(java.net.SocketPermission phc:8000 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.plugin.protocol.jdk12.http.HttpURLConnection.connectStep1(Unknown
> >Source)
> >at sun.plugin.protocol.jdk12.http.HttpURLConnection.connect(Unknown Source)
> >at Veiculos_Panel.getFromServlet(Veiculos_Panel.java:712)
> >at Veiculos_Panel.procuraButtonActionPerformed(Veiculos_Panel.java:615)
> >at Veiculos_Panel$5.actionPerformed(Veiculos_Panel.java:426)
> >at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> >at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
> >Source)
> > at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
> Source)
> > at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> >at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
> >at java.awt.Component.processMouseEvent(Unknown Source)
> >at java.awt.Component.processEvent(Unknown Source)
> >at java.awt.Container.processEvent(Unknown Source)
> >at java.awt.Component.dispatchEventImpl(Unknown Source)
> >at java.awt.Container.dispatchEventImpl(Unknown Source)
> >at java.awt.Component.dispatchEvent(Unknown Source)
> >at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> >at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> >at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> >at java.awt.Container.dispatchEventImpl(Unk
>nown Source)
> >at java.awt.Component.dispatchEvent(Unknown Source)
> > at java.awt.EventQueue.dispatchEvent(Unknown Source)
> >at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
> >at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> > at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> > at java.awt.EventDispatchThread.run(Unknown Source)
> >
> >
> >And my java.policy file looks like this:
> >
> >grant {
> >permission java.security.AllPermission;
> >};
> >
> >Thanks for your help.
> >
> >Hugo Malheiro
> >
> >
> >-----Original Message-----
> >From: A mailing list for discussion about Sun Microsystem's Java Servlet
> >API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> >Sohaila Roberts
> >Sent: quinta-feira, 20 de Setembro de 2001 15:10
> >To: [EMAIL PROTECTED]
> >Subject: Re: java.net.ConnectException in applet connection to servlet
> >
> >
> >try putting the actual server's name that the servlet is running on,
> >instead of localhost
> >
> > > URL url = new
> >URL("http://localhost:8000/main?"+URLEncoder.encode("opcao")+
> > >
> >"="+URLEncoder.encode(opcao)+"&"+URLEncoder.encode("param")+
> > >
> >"="+URLEncoder.encode(param));
> > > URLConnection con = url.openConnection();
> > > con.setDoOutput( true );
> > > con.setDoInput( true );
> > > con.setUseCaches( false );
> > > con.setDefaultUseCaches(false);
> > > InputStream in = con.getInputStream();
> > > ObjectInputStream objStream;
> > > objStream = new ObjectInputStream(in);
> > > obj = (Object)objStream.readObject();
> > > objStream.close();
> > > in.close();
> > >
> > > }catch(IOException o){o.printStackTrace();}
> > > catch(ClassNotFoundException c){c.printStackTrace();}
> > >
> > >
> > > return obj;
> > > }
> > >
> > > (I return an object some that i can use the same function in diferent
> > > places)
> > >
> > > I've looked in the archives and in search engines for this exception,
>but
> >i
> > > did not find anything relevant. Some if anyone can help me i would
> >apreciate
> > > it.
> > >
> > > Thanks for you time.
> > > Hugo Malheiro
> > >
> > >
> >___________________________________________________________________________
> > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> >body
> > > of the message "signoff SERVLET-INTEREST".
> > >
> > > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > > Resources: http://java.sun.com/products/servlet/external-resources.html
> > > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> > >
> >
> >___________________________________________________________________________
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> >of the message "signoff SERVLET-INTEREST".
> >
> >Archives: http://archives.java.sun.com/archives/servlet-interest.html
> >Resources: http://java.sun.com/products/servlet/external-resources.html
> >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
> >___________________________________________________________________________
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> >of the message "signoff SERVLET-INTEREST".
> >
> >Archives: http://archives.java.sun.com/archives/servlet-interest.html
> >Resources: http://java.sun.com/products/servlet/external-resources.html
> >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html