The scripting APIs for the Java platform in general and Nashorn in particular offer a wide range of opportunities for developing web applications on the JVM. Framework such as node.js and vert.x solvency JavaScript as a server structure. Yes, we are still awaiting news about node.jar, the mysterious Oracle project to implement the node.js API on the Java platform.
In today's modern web applications, we should think of the server side as a RESTful services, rather than the presentation structure that generates html on the server. But even for server pages, you donβt have to adhere to such frameworks as JSF, Wicket, ADF. With Nashorn / Rhino, you can use JavaScript templates to generate html markup for the backend. LinkedIn, for example, has already described the benefits of having templates written in JavaScript in both the browser and server. In case your browser fails to compress client templates, you can competently degrade and switch to server-side rendering.
If you are looking for an example of using JavaScript in a server side web environment, you can start with Dust4j . Do not confuse the words Rhino in the description. Dust4j does not use Rhino's internal APIs. It uses the jsr223 API, so if you run it on JDK8 or JDK7 using the Nashorn backport , it should work. The Dust4j project shows how you can integrate scripts in your JSP / Servlet / Filter application.
source share