admin管理员组文章数量:1326461
Im using "react": "~0.12.2"
And the following code:
@RequestMapping("/")
@ResponseBody
private String home() throws ScriptException, IOException {
loadReact();
InputStream jsStream = resourceLoader.getResource("classpath:public/js/server.js").getInputStream();
engine.eval(new InputStreamReader(jsStream));
return engine.eval("renderServerside()").toString();
}
private void loadReact() throws ScriptException, IOException {
InputStream jsStream = resourceLoader.getResource("classpath:public/lib/react/react.js").getInputStream();
// React expects 'window' or 'global' to be set
engine.eval("var global = this");
engine.eval(new InputStreamReader(jsStream));
}
My server.js looks like this:
function renderServerside() {
var MyComponent = React.createClass({
render: function () {
return React.DOM.h1(null, 'Hi, ' + this.props.msg)
}
});
return React.renderComponentToString(MyComponent({msg: 'World!'}));
}
And getting this exception:
javax.script.ScriptException: ReferenceError: "console" is not defined in <eval> at line number 18108] with root cause
jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "console" is not defined
So how can nashorn not provide a console?
I tired to implement the basic example from this page: React with Nashorn
Im using "react": "~0.12.2"
And the following code:
@RequestMapping("/")
@ResponseBody
private String home() throws ScriptException, IOException {
loadReact();
InputStream jsStream = resourceLoader.getResource("classpath:public/js/server.js").getInputStream();
engine.eval(new InputStreamReader(jsStream));
return engine.eval("renderServerside()").toString();
}
private void loadReact() throws ScriptException, IOException {
InputStream jsStream = resourceLoader.getResource("classpath:public/lib/react/react.js").getInputStream();
// React expects 'window' or 'global' to be set
engine.eval("var global = this");
engine.eval(new InputStreamReader(jsStream));
}
My server.js looks like this:
function renderServerside() {
var MyComponent = React.createClass({
render: function () {
return React.DOM.h1(null, 'Hi, ' + this.props.msg)
}
});
return React.renderComponentToString(MyComponent({msg: 'World!'}));
}
And getting this exception:
javax.script.ScriptException: ReferenceError: "console" is not defined in <eval> at line number 18108] with root cause
jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "console" is not defined
So how can nashorn not provide a console?
I tired to implement the basic example from this page: React with Nashorn
Share Improve this question edited Jan 20, 2015 at 16:17 daniula 7,0284 gold badges35 silver badges49 bronze badges asked Dec 24, 2014 at 12:14 TarionTarion 17.2k13 gold badges77 silver badges113 bronze badges1 Answer
Reset to default 8Rhino before it didn't provide one either. You can implement your own console with something like
console = {
log: print,
warn: print,
error: print
};
For full blown console support you might need to add more functions. See: Console
版权声明:本文标题:java - Using React with Nashorn throws "ReferenceError: "console" is not defined" - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742209954a2433525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论