JSP-JS is a Java Server Pages rendering library for nodejs.
To render JSP to HTML, simply remove Java code. Currently supported tags are:
<%@include%>
<%@taglib tagdir="[path]">
<%=..%>
${..}
<c:if>
<c:else>
<c:choose>
<c:when>
<c:otherwise>
<c:forEach>
<c:set>
<jsp:body>
<jsp:doBody>
<jsp:attribute>
<jsp:invoke>
Run:
npm run demo
Then open your browser to http://localhost:8080/page/test.jsp
.
Import he renderer like so:
const JSPJs = require('jsp-js').Renderer;
const jsp = new JSPJs(options);
jsp.render('file', data);
The renderer also provides a promise wrapper for easy integration in promise-based code:
jsp.renderPromise('file', data).then((html) => console.log(html));
The following options can be provided to the constructor:
root
: the root path where templates aretags
: a library of custom tagsglobals
: globally available dataCustom tags can be handled by providing them to the constructor options. These are anonymous functions that take the arguments:
node
the tag node being evaluatedindex
the position of the node in the jsp template. Useful for debuggingdata
the current context data (as an object)renderer
the instanciated rendererA custom tag handler must return a string.
Please read the code of test/tests.js
to have an idea of how to integrate this
library with Express.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。