velocity

Ok, lets start off with some easy examples. These examples really do not even touch on the basics of correct design. However, they still make good examples because correct design is often harder than showing a simple example. We will show better examples further along in this essay.

For the first example, we show that there are two different approaches of doing the same exact thing using both JSP and Velocity. This is an example of printing out a parameter with JSP:

<html>
<head><title>Hello</title></head>
<body>
<h1>
<%
if (request.getParameter("name") == null) {
   out.println("Hello World");
}
else {
  out.println("Hello, " + request.getParameter("name"));
}
%>
</h1>
</body></html>

This is an example of doing the same thing with Velocity:

<html>
<head><title>Hello</title></head>
<body>
<h1>
#if ($request.getParameter("name") == null)
   Hello World
#else
   Hello, $request.getParameter("name")
#end
</h1>
</body></html>
原文地址:https://www.cnblogs.com/lexus/p/2580635.html