-1

I'm trying to get windows username from liferay portlet in java code using javascript and active-x. When I run the code only with javascript and acitive-x on plain HTML it works. But when I put it in java, it doesn't work. Here is my code:

String script = "function getUser() {return ((new ActiveXObject('WScript.NetWork')).UserName); }";  
try {
    engine.eval(script);
} catch (ScriptException e) {
    e.printStackTrace();
}  

Invocable inv = (Invocable) engine;  

try {
    log.info("try invoke script");
    String teste = (String) inv.invokeFunction("getUser");
    log.info("meu teste " +teste);
} catch (ScriptException e) {
    e.printStackTrace();
} catch (NoSuchMethodException e) {
    e.printStackTrace();
}

When I change the content on function for somthing else like returning string it prints the result.

BackSlash
  • 21,927
  • 22
  • 96
  • 136
  • S3iB, does it returns the user who are acessing the page or the user loggen on the server? – user2661250 Jan 23 '14 at 13:01
  • S3iB, your answer doesn't solve my problem. I want the user who a acessing the page rather than user who a logged in to server wich is always same! – user2661250 Jan 23 '14 at 14:05

1 Answers1

2

Java-s JavaScript doesn't have Active X capabilities, but you don't have to use JavaScript to get the running machines users username. Get login username in java

If you want to know client-s OS-s username then one approach would be to use client side JavaScript to find it out and submit this information to server side via AJAX.

Community
  • 1
  • 1
Tarmo
  • 3,851
  • 2
  • 24
  • 41