Introduction:
Let's compare two large websites:
51job and Zhaopin (first, I declare that I am not making advertisements for them. I only use them as an example for technical comparison)
51job uses a relatively "advanced" php technology, while Zhaopin uses a relatively backward asp. however, we may obviously feel that the reaction speed of 51job is too slow than that of Zhaopin. Why? Careful people may notice it. Although zstack uses asp, it uses another Clever technology, asp, to generate static pages. All dynamic pages are converted to html static pages without accessing the database. Of course, the response is faster.
Next we will discuss how to convert jsp into html ??
First, create a template. The suffix is not limited, but it is generally used in the *. template example.
<Html>
<Head>
<Title> # title # </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<LINK href = "../css.css" rel = stylesheet type = text/css>
</Head>
<Body>
<P align = "center">
# Title # <BR>
Author: # author # <BR>
<BR>
# Content # <BR>
</P>
</Body>
</Html>
Create a class or jsp file for processing the template (to illustrate the problem, we will start with a jsp file as an example)
FilePath = request. getRealPath ("/") + "WEB-INF/templates/template.htm ";
Out. print (filePath );
String templateContent = "";
FileInputStream fileinputstream = new FileInputStream (filePath); // read the module File
Int lenght = fileinputstream. available ();
Byte bytes [] = new byte [lenght];
Fileinputstream. read (bytes );
Fileinputstream. close ();
TemplateContent = new String (bytes );
Out. print ("The following is the template content: <br>" + templateContent + "<br> The following is the html content after replacement <br> TemplateContent = templateContent. replaceAll ("# title #", title );
TemplateContent = templateContent. replaceAll ("# author #", editer); // replace the corresponding part of the module
TemplateContent = templateContent. replaceAll ("# content #", content );
// Get the file name by Time
Calendar calendar = Calendar. getInstance ();
String fileame = String. valueOf (calendar. getTimeInMillis () + ". html ";
Fileame = request. getRealPath ("/") + fileame; // the path for saving the generated html file
Out. print (templateContent );
FileOutputStream fileoutputstream = new FileOutputStream (fileame); // create a file output stream
Byte tag_bytes [] = templateContent. getBytes ();
Fileoutputstream. write (tag_bytes );
Fileoutputstream. close ();
Well, the core technology is like this. If you require higher performance, you can use freemarker as a template.