private native String getIP() /*-{
var ip = @java.net.InetAddress::getLocalHost() ();
var ipStr = ip.@java.net.InetAddress::getHostAddress() ();
return ipStr;
}-*/;
It works fine on the hosted mode but when I try to compile I get the
following error
Output will be written into C:\Java
development\SAGEUI\www\evl.sage.SageUI
Analyzing permutation #1
Errors in file:/C:/Java
development/SAGEUI/src/evl/sage/client/SageDisplay
.java
[ERROR] Line 300: Unresolvable native reference to type
'java.net.Inet
Address'
[ERROR] Line 300: Unresolvable native reference to type
'java.net.Inet
Address'
[ERROR] Unexpected internal compiler error
[ERROR] Build failed
Can someone help me with this issue,
Thanks,
Javid
When you compile GWT code, the service code resides in the server and
the UI code gets converted in Javascript code. Since you can't access
java.net code in Javascript, the compiler doesn't compile such code
either.
Try the following:
EntryPoint.jsp
<!-- Use a jsp instead of an HTML, you need to get data from the
server to the browser -->
<script language="javascript">
<%
String ip_address = getHostAddress(); // that's code to get the
client's IP address
%>
var _ipAddress = <%= ip_address %>;
// var _ipAddress = "10.0.0.1";
</script>
<!-- remainder of your jsp page -->
Now, in the Java code, use something like:
private static native JavaScriptObject getIP() /*-{
return $wnd._ipAddress;
}-*/;
private void someFunction(){
String client_ip = getIP().toString();
}
What I've done here is :
1. Assemble a client specific page containing the client's IP address.
2. Send this to the client.
3. Include within this page the gwt bootstrap code.
4. Write some GWT code that makes a Javascript call. The call seeks
the variable _ipAddress in the Window object.
I've tried the above and it works for me.
-- Sriram
Er.. I'd told you about getHostAddress() intending it to be code
that'll return to you the remote Address.
Replace String ip_address = getHostAddress();
with:
String ip_address = request.getRemoteAddr();
> Thanks,
> Javid
-- Sriram
True.
However, thinking in the GWT way of web app development requires some time.
-- Sriram