As response to an Ajax-request I want to return Javascript that is executed on the client immediately. I tried it like this but it doesn\'t work:
writer.write("alert(’Works!’);");
Curly quotes are not a valid string delimiter in JS. Use straight quotes.
writer.write("alert('Works!');");
Unrelated to the concrete problem, based on your question history you're using PrimeFaces, or at least familiar with it. In that case, just use RequestContext#execute() instead of this mess.