1. ReactJS - Server side Rendering Using Java(jdk1.7)
<%
String
output="var value=[]";
ScriptEngineManager
sem = new
ScriptEngineManager();
ScriptEngine
se = sem.getEngineByName("rhino");
//
React depends on the "global" variable and console variable
se.eval("var
global = this");
se.eval("var
console = {}");
se.eval("console.warn
= function(){};");
//
eval react.js
se.eval(new
FileReader("/react-0.12.2.js"));
// React Location
se.eval(output);
// variable for component props
se.eval(new
FileReader("/Component.js"));
// React Component location (Component
should be converted js file not jsx file)
String
render ="React.renderToString(React.createFactory(Component)({props:
value}))";
%>
<%=se.eval(render)%>
// execute the component get html as a
string
No comments:
Post a Comment