title: Script Exception while parsing an java.object to ScriptEngine
body: <p>What i'm trying to do is to parse in browser address bar a json object through java code. The JSON object i want to to obtain should be:</p>
  
  <pre><code>{idUtente : "idUtente"}
  </code></pre>
  
  <p>So i implemented this code</p>
  
  <pre><code>public void inviaMailConferma(Utente utente) throws Exception {
  
      SimpleMailMessage message = new SimpleMailMessage();
      message.setTo(utente.getEmail());
      message.setSubject("Conferma registrazione a Portfolio Online");
      InetAddress ip = InetAddress.getLocalHost();
      ScriptEngineManager factory = new ScriptEngineManager();
      ScriptEngine engine = factory.getEngineByName("JavaScript");
      String idUtente = utente.getUsername();
      Object eval = engine.eval("print(encodeURIComponent(idUtente))");
      message.setText("Ciao " + utente.getUsername() + "! Per registrarsi al sito, cliccare il seguente link: " + ip.getHostAddress() + ":8084/VenditaGioielli/confermaRegistrazione?data=" + eval.toString());
      mailSender.send(message);
  
  }
  </code></pre>
  
  <p>when i run engine.eval, i'm gettin this Exception</p>
  
  <pre><code>ex = (javax.script.ScriptException) javax.script.ScriptException:
  sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "idUtente" is not
  defined. (&lt;Unknown source&gt;#1) in &lt;Unknown source&gt; at line number 1
  </code></pre>
  
  <p>I don't know how to parse a java Object to engine.val! </p>
  
  <p>EDIT</p>
  
  <p>now i came to this code</p>
  
  <pre><code> ScriptEngine engine = factory.getEngineByName("JavaScript");
   String idUtente = utente.getUsername();
   engine.put("idUtente", idUtente);
   Object eval = engine.eval("print(encodeURIComponent(idUtente))");
  </code></pre>
  
  <p>but engine.eval returns null!</p>
  
  <p>EDIT</p>
  
  <p>now i come to this code</p>
  
  <pre><code> ScriptEngineManager factory = new ScriptEngineManager();
   ScriptEngine engine = factory.getEngineByName("JavaScript");
   ScriptContext scriptContext = new SimpleScriptContext();
   Bindings binding = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
   String idUtente = utente.getUsername();
   engine.put("idUtente", idUtente);
   Object eval = engine.eval("print(encodeURIComponent(idUtente))", binding);
  </code></pre>
  
  <p>and i have the following exception:</p>
  
  <pre><code>"sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "idUtente" is not defined. (&lt;Unknown source&gt;#1)"
  </code></pre>