• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

connecting servlet from applet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic