[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid Applet question




This could be eaily generated on the fly but does not work on a server
with multiple IP's


On Tue, 2002-11-19 at 13:26, Kent Fletcher wrote:
> This will only return the clients IP, not the servers IP.  Send the IP (or hostname)  to the client via an argument to the applet.
> 
> eg. Your applet spec is embedded in an html, so set the PARAM tag using a key of your choice.   You can dynamically populate this value in your html applet document to the appropriate IP at runtime if you want to get fancy, or you can hard code it for now.
> 
> Then in your applet, use  String ip = (String) applet.getParameter("SERVER_IP");  
> 
> <HTML>
>  <HEAD>
>   <TITLE>yourpackage Applet</TITLE>
>  </HEAD>
>  <BODY>
>  <OBJECT
>   classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
>   WIDTH="1"
>   HEIGHT="1"
>   codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0";>
>   <PARAM NAME="code" VALUE="yourpackage.YourApplet" >
>   <PARAM NAME="archive" VALUE="yourpackage.jar,jaxp.jar,jdev_rt.zip,xalan.jar,CalendarBean.jar,crimson.jar" >
>   <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">
>   <PARAM NAME="scriptable" VALUE="false">
>   <PARAM NAME="SERVER_IP" VALUE="whateverYourServersIPIS" >
>   <COMMENT>
>   <EMBED
>    type="application/x-java-applet;version=1.2.2"
>    code="yourpackage.YourApplet"
>    archive="yourpackage.jar,jaxp.jar,jdev_rt.zip,xalan.jar,CalendarBean.jar,crimson.jar"
>    width="640" HEIGHT="480"
>    scriptable=false
>    pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html";>
>   <NOEMBED>
>   </COMMENT>
>    No JDK 1.2 support for APPLET!!
>   </NOEMBED>
>  </EMBED>
>  </OBJECT>
> 
> </BODY>
> </HTML>
> 
> 
> 
> 
> ----- Original Message ----- 
> From: "Mahmoud Ahmed" <mkahmed_99@yahoo.com>
> To: "cfowler" <cfowler@outpostsentinel.com>; <ajug-members@ajug.org>
> Sent: Tuesday, November 19, 2002 12:33 PM
> Subject: Re: Stupid Applet question
> 
> 
> > Chris,
> > 
> > If the applet is a trusted applet here how can you get
> > name and ip adress:
> > 
> > 
> > import java.applet.Applet;
> > import java.awt.Label;
> > import java.net.InetAddress;
> > 
> > 
> > public class HostInfoApplet extends Applet {
> >    private Label lhostAddress;
> >    private Label lhostName;
> >    private static String hostAddress;
> >    private static String hostName;
> > 
> > 
> >    public void init() {
> >       setHostInfo();
> >    }
> >    public void start() {
> >       printHostInfo();
> >       lhostAddress = new Label("HostAddress: " +
> > getHostAddress());
> >       add(lhostAddress);
> >       lhostName = new Label("HostName: " +
> > getHostName());
> >       add(lhostName);
> > 
> >    }
> >    public void stop() {
> >       remove(lhostAddress);
> >       remove(lhostName);
> >    }
> > 
> >    public String getHostAddress() {
> >       return this.hostAddress;
> >    }
> >    public String getHostName() {
> >       return this.hostName;
> >    }
> > 
> >    private void setHostInfo()
> >    {
> > try {
> > InetAddress ina = InetAddress.getLocalHost();
> > hostAddress = ina.getHostAddress();
> > hostName = ina.getHostName();
> > ina = null;
> > }
> > catch(Exception e) {
> > e.printStackTrace();
> > }
> >    }
> > 
> >    public void printHostInfo()
> >    {
> >   System.out.println("Host Address: " + hostAddress);
> >   System.out.println("Host Name: " + hostName);
> >    }
> > }
> > ====== index.html ========
> > <title>HostInfo Applet</title>
> > <hr>
> > <applet code="HostInfoApplet.class" width=300
> > height=100>
> > </applet>
> > <hr>
> > ====== end index.html =====
> > 
> > 
> > --- cfowler <cfowler@outpostsentinel.com> wrote:
> > > In an applet, How can I get the IP Address of my
> > > server since I'm only
> > > allowed to connect to that server?
> > > 
> > > Thanks,
> > > Chris
> > > 
> > > 
> > > 
> > 
> > 
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Web Hosting - Let the expert host your site
> > http://webhosting.yahoo.com