aspose file tools*
The moose likes Servlets and the fly likes connecting servlet from applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "connecting servlet from applet" Watch "connecting servlet from applet" New topic
Author

connecting servlet from applet

Fahad tebateba
Greenhorn

Joined: Jan 05, 2003
Posts: 10
when i run the applet i got the following error while connecting to the servlt from applet
here the following error
com.ms.security.SecurityExceptionEx[Appl.init]: cannot access "127.0.0.1":8080
hree the applet code
import java.applet.*;
import java.awt.*;
import java.net.*;
public class Appl extends Applet
{
String alt,paraSub,urlmsg,error,message;
public void init()
{
alt = getParameter("alt");
paraSub = getParameter("parasub");
URL url = getCodeBase();
urlmsg = " code base => " +url.toString();
url = getDocumentBase();
urlmsg+= " documebt base => "+url.toString();
urlmsg+=alt;
urlmsg+=paraSub;
String location = "http://127.0.0.1:8080/servlet/Test?urlmsgserv="+URLEncoder.encode(urlmsg);
try
{
URL testServlet = new URL(location);
URLConnection servletConnection = testServlet.openConnection();
servletConnection.connect();
}
catch(Exception exp)
{
error="there is some error starting srevlet"+exp;
repaint();
}
}
public void paint(Graphics g)
{
g.drawString(urlmsg,5,10);
g.drawString(alt,5,30);
g.drawString(paraSub,5,60);
g.drawString("the servlet has been started",5,85);
g.drawString(error,5,95);
}
}

====================
heres the servlet code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;
public class Test extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws java.io.IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws java.io.IOException
{
String filename = "mymailtest.t";
FileWriter resultsFile = new FileWriter(filename,true);
PrintWriter toFile = new PrintWriter(resultsFile);
Date date = new Date();
urlmsgServ = request.getParameter("urlmsgserv");
toFile.println(" url message is => "+urlmsgServ) ;

resultsFile.close();
toFile.close();
}
}
Cory Wilkerson
Ranch Hand

Joined: Aug 14, 2001
Posts: 84
Before digging into this...are you servlet and applet runding under the same application context or are you running the applet at myhost.com/someapp and the other at myhost.come/someotherapp? Exactly what is your configuration here?
Thanks!
Cory
Fahad tebateba
Greenhorn

Joined: Jan 05, 2003
Posts: 10
my applet class file is in c:\files while the servlet which will it hits is present in c:\javawebserver\servlets\
i m using javawebserver
hope this will help
hope to c ya
-fahad.
Cory Wilkerson
Ranch Hand

Joined: Aug 14, 2001
Posts: 84
Fahad,
Make sure that your applet and your servlet (when deployed) reside on the same host. If they don't, you'll run into all manner of security exceptions. Applets can communicate only with their host server -- that said, make sure they're in the same place.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connecting servlet from applet