News has not only been published so far, but I have also published news that can generate static pages before. However, I always feel that it is not very professional and inefficient.
Apache velocity has been found. It can be used in many fields. Currently, it is only used to display pages in struts to avoid overload of the same URL (such as shownews. do, maybe n people watch the news at the same time. The detailed content of this news shows that the URL load is too heavy ). Well, the general principle is as follows:
The template (H. VM) only provides some static characters, with some classes such as $ title "wildcard" added in the middle, which should be replaced in helloworld. java. Below is the H. VM'sCode:
Hello $ name ! Welcome to $ site world !
Helloworld. Java is processingProgramThe annotations are clearly written. The following is the code of helloworld. Java:ImportJava. Io. stringwriter;
ImportOrg. Apache. Velocity. App. velocity;
ImportOrg. Apache. Velocity. App. velocityengine;
ImportOrg. Apache. Velocity. template;
ImportOrg. Apache. Velocity. velocitycontext;
Public Class Helloworld {
Public Static Void Main (string [] ARGs) Throws Exception {
// Initialize the velocity template engine
Velocityengine ve = New Velocityengine ();
Ve. INIT ( " D: \ working \ velocity \ AAAA \ bin \ A. Properties " );
// Velocity obtains the template file and obtains the template reference.
Template t = Ve. gettemplate ( " H. VM " );
// Initialize the environment and put the data into the environment
Velocitycontext Context = New Velocitycontext ();
Context. Put ( " Name " , " Zz " );
Context. Put ( " Site " , " Http://amboyna.cnblogs.com " );
// Combine environment variables with output
Stringwriter writer = New Stringwriter ();
T. Merge (context, writer );
System. Out. println (writer. tostring ());
}
}
Here, the main role of the configuration file is to provide the path, not to mention, the following is the code of A. properties:Runtime. Log=Velocity_example.log
Input. Encoding=GBK
Output. Encoding=GBK
File. Resource. loader. Path=D: \ working \ velocity \ AAAA \ bin
Finally, complete the acquisition ....
By the way, click to download the program code. Program code
For a complete introduction to Apache velocity, refer to this: Use the Apache velocity template engine to quickly create a website.