|[ Team LiB ]|
The JspEngineInfo Class
Occasionally you might want to obtain information about the current version of the JSP engine. You might even have code that adapts itself to various versions of the JSP specification. For example, you might create a JSP that takes full advantage of the features of JSP version 2.0 and another page that runs under JSP 1.2 but doesn't do everything the 2.0 page does. By examining the current version of the JSP engine, you can decide which page to call.
The JspEngineInfo class defines just one method, which returns a string containing the current version number of the JSP engine. The version number is a series of numbers separated by periods, such as 2.0 or 18.104.22.168.5. The getSpecificationVersion method returns the current version number:
public String getSpecificationVersion()
You must take a roundabout path to get to the JspEngineInfo object. You must get the object from a JspFactory object. The JspFactory class is used internally by the JSP engine and by the generated servlets. Typically a single JspFactory, which is called the default factory, is used by all the JSPs. To get the default factory, just call getDefaultFactory:
JspFactory defaultFactory = JspFactory.getDefaultFactory();
After you have the JspFactory, you can call getEngineInfo to retrieve the JspEngineInfo object:
JspEngineInfo engineInfo = defaultFactory.getEngineInfo();
Listing 8.3 shows a JSP that prints out the version of the JSP specification that the current JSP engine supports.
<html> <body> The current JSP Engine is: <%= JspFactory.getDefaultFactory().getEngineInfo(). getSpecificationVersion() %> </body> </html>
Figure 8.3 shows the output from PrintEngineInfo.jsp.
You Can Use JspFactory
|[ Team LiB ]|