⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 velocity.xtp

📁 解压在c盘
💻 XTP
字号:
<s1 title="Velocity-Style Syntax"><p>The Apache <a href="http://jakarta.apache.org/velocity">Velocity</a>project introduces an alternative syntax to the familiar JSPexpressions and scriptlets.  Resin's extension allows the useof Velocity-style syntax in JSP files.  The Velocity-style syntaxis transformed into JSTL standard tags.</p><p>The syntax is based on expressions like <var/${foo}/>and scriptlets with <var/#{...}#/>.  Because thealternative syntax avoids the brackets which fill JSP pages, it can makepages more readable and therefore more maintainable.</p><p>Because Resin's Velocity-style syntax is transformed to the JSTLtag library, all JSTL expressions are allowed.</p><example title='JSP style'>&lt;%int count;%>&lt;h3>A sample &lt;%= count %>&lt;/h3>&lt;% if ("foo".equals(request.getParameter("a"))) { %>  &lt;h3>Foo!&lt;/h3>&lt;% } else { %>  &lt;h3>Bar!&lt;/h3>&lt;% } %></example><p>The same JSP file could be written in Velocity-style as follows.  Thejsp:directive is required because JSP pages use strict JSP syntaxby default.</p><example title='Velocity style'>&lt;jsp:directive.page velocity='true'/>#{int count;}#&lt;h3>A sample ${count}&lt;/h3>#if ("foo" == params.a)  &lt;h3>Foo!&lt;/h3>#else  &lt;h3>Bar!&lt;/h3>#end</example><p>The choice between the two is a matter of preferences.  An advantageof the velocity style is that expressions and scriptlets avoid usingbrackets.  In large pages, sorting out the HTML or XML from the JSP syntaxcan become confusing.</p><s2 title="Enabling velocity-style syntax"><p>Velocity-style syntax can either be enabled on a per-JSP page wit<var/velocity='true'/> or in the web-app with the &lt;jsp> tag:</p><example title='Enabling velocity for a web-app'>&lt;web-app>  &lt;jsp velocity='true'/>  ...&lt;/web-app></example></s2><s2 title='expressions'><p>Expressions are enclosed between "${" and "}", for example'${count}' and '${count + 15}'.</p><p>The '${...}' syntax is equivalent to '<var>&lt;c:out value="..."/></var>'.</p><def>${<var/expression/>}</def></s2><s2 title='scriptlets'><p>Scriptlets use the '#{ ... }#' syntax.  This is entirely equivalent to'&lt;% ... %>'.  (Note, Velocity does not have this syntax because itcreates its own language instead of escaping to Java.)</p><def>#{ <var/statements/>}#</def><example>#{String key = request.getParameter("key");if (key.equals("")) {  response.sendError(500, "Bad key");  return;}}#...</example></s2><s2 title='if statements'><p>The velocity-style syntax directly supports if statements.  The syntax is</p><def>#if (expr1)  ...#elseif (expr1)  ...#else  ...#end</def><p>The expressions can be any JSTL expression.  The if statement is transformed into:</p><example>&lt;c:choose>&lt;c:when test="${<var/expr1/>}">  ...&lt;/c:when>&lt;c:when test="${<var/expr2/>}">  ...&lt;/c:when>&lt;c:otherwise>  ...&lt;/c:otherwise>&lt;/c:choose></example></s2><s2 title='foreach statements'><p>The velocity-style syntax directly supports iteration with a foreachstatements.</p><def>#foreach (var in expr)  ...#end</def><p>This style of foreach is transformed into the following:<example>&lt;c:forEach items="${<var/expr/>}" var="<var/var/>">  ...&lt;/c:forEach></example><p>An example use might be the following:</p><example title='foreach in Java'>&lt;jsp:page velocity='true' import='java.lang.*'/>#{  ArrayList list = new ArrayList();  list.add("foo");  list.add("foobar");  pageContext.setAttribute("list", list);}##foreach (value in list)  &lt;li>${value}#end</example><p>The velocity-style syntax also supports integer iteration.</p><def>#foreach (var in [begin .. end])  ...#end</def><p>The range is transformed into the following:</p><example>&lt;c:forEach begin="${<var/begin/>}" end="${<var/end/>}" var="<var/var/>">  ...&lt;/c:forEach></example><p>An example might be the following:</p><example title='foreach in Java'>&lt;jsp:page velocity='true'/>#foreach (value in [3..9])  &lt;li>$value#end</example></s2></s1>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -