Hi advit,
Here I am giving you the code, it will help you for your problem.
import java.applet.*;
import java.awt.*;
import java.net.*;
public class host extends Applet
{
String hostname;
public void init()
{
try
{
InetAddress localAddress = InetAddress.getLocalHost();
hostname = localAddress.getHostName();
} catch(Exception e)
{
hostname = "Unknown";
}
}
public void paint(Graphics g)
{
FontMetrics fm;
/* by using g .drawRect or square you define dimensions here,
after that getfonts using g.getfont() */
FontMetrics metrics = g.getFontMetrics ();
int messageWidth = metrics.stringWidth (hostname);
int startX = size().width/2 - messageWidth/2;
int startY = size().height/2 - fontDescent/2 + fontAscent/2;
g.drawString (hostname,startX, startY);
}
}
I hope this will help you out.
Regards,
Tirumalarao
Developer Technical Support,
Sun Microsystems,India.
Not sure what exactly you want to do.
If you just want to know the client's hostname in a JSP page, use request.getRemoteHost().
If you want to be able to use it in an applet, then just pass it to the applet as a parameter:
<applet ...>
<param name='hostname' value='<%= request.getRemoteHost() %>'>
</applet>