Why JSP pages are static.
The so-called JSP page static refers to the dynamic JSP page generated static HTML page, through the direct access to the generated HTML to obtain and access JSP the same display content and application functions.
JSP or dynamic page technology is to solve the problem of static HTML (unable to dynamically obtain data), then why now to do the work of the page static. Mainly because the page static can bring two main benefits: one is the improvement of access performance, the second is the lower background database pressure.
JSP is returned to the final browser client after it is converted to a document stream through the JSP parsing engine. So if it has been generated for HTML, such access will save the JSP engine parsing work, natural access performance is good, especially in the case of large server pressure, the performance gap between the two significant. In addition, the general JSP page will need to read data from the background, in advance, the static will be less to go to every visit to query the database steps, the natural database pressure will also be reduced.
which pages are statically formatted.
Not all JSP pages are suitable for static, static at the expense of dynamic real-time access to data, so for those who need real-time access to database data page is not suitable for static. The most common example of static is the news, because after the release is basically not modified, so this type of content page should be the most static page. In fact, this kind of content is usually done through a variety of CMS, and do not need programmers to do their own.
freemaker and Page statics
Freemaker and page Static in fact, there is no inevitable connection, at best, is a solution. It is similar to JSP in nature, all by the relevant engine to parse the template to generate the final document content.
Static Technology
For the static JSP page here introduces a simple method,Httpclient+urlrewrite, especially for the existing JSP application static implementation is relatively simple.
using httpclient to generate static HTML
Import Java.io.File;
Import Java.io.FileWriter;
Import org.apache.commons.httpclient.HttpClient;
Import Org.apache.commons.httpclient.methods.GetMethod;
public class Testhttpclient {public
static void Main (string[] args) {
httpclient client = new HttpClient ();
GetMethod GetMethod = new GetMethod ("http://192.10.110.88:8080/test/index.jsp");
String Path=testhttpclient.class.getclassloader (). GetResource (""). GetPath ();
Path=path.substring (0,path.indexof ("web-inf/classes/")) + "static/";
try {
Client.executemethod (getmethod);
File File = new file (path+ "index.html");//save to the applied static directory
FileWriter writer = new FileWriter (file);
Writer.write (Getmethod.getresponsebodyasstring ());
Writer.flush ();
} catch (Exception e) {
e.printstacktrace ();}}}
the role of Urlrewrite.
URL redirection can be done using urlrewrite, which is good for static for existing JSP applications, because only a configuration can make it possible to redirect access to dynamic JSP page requests to the generated HTML, and basically do not need to change the original code. Basically, there are two steps:
1) Download the Urlrewritefilter-4.0.3.jar and put it under Web-inf/lib.
2 Add a filter to the Web-inf/web.xml, Note: If you also define other filter, it is recommended to put the filter on the front.
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class> org.tuckey.web.filters.urlrewrite.urlrewritefilter</filter-class>
</filter>
< filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</ url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>forward</dispatcher >
</filter-mapping>
Detailed configuration can refer to http://tuckey.org/urlrewrite/
static with Ajax pages now Ajax technology has been very widely used, for Ajax-containing JSP pages to implement static will be a lot of trouble. htmlunit This tool can simulate AJAX requests, but there are still a lot of problems. Most commonly, when using jquery, the AJAX request is often executed after the page is loaded, in which case, even if the HTML is statically generated, the AJAX request is sent again to the HTML access, so that the role of the page static is compromised. Some people suggest that you can use Jsoup, such as parsing documents, eliminate the need to execute the script, the reality is this difficult, take the use of jquery, the common situation is that the page after the completion of the load, in addition to sending AJAX requests will also register for DOM elements listening events, etc. The function of the page is not normal. So if the JSP containing AJAX requests must be static, the most cost-effective way is to rewrite or rewrite the original function interface, the page initialization after the automatic implementation of the AJAX request to remove, change to the relevant data one-time return.