|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
SSSI - Simple Server Side Includes - must implement this interface.
SSSI are directives that are placed in static HTML pages, and evaluated on the server while the HTML pages are being served. They let you add the result of a dynamically called java class (SSSI) to the content of a static HTML page, without having to serve the entire page via a Weblet.
Programming Example: HTML File
<HTML>
<BODY>
Current Time = <!-- @mypackage.CurrentTimeTestSssi("ECT") -->
</BODY>
</HTML>
Programming Example: Java Class
package mypackage;
import dfischer.femtowebserver.httpd.*;
dfischer.femtowebserver.lib.ZoneTime;
public class CurrentTimeTestSssi implements HttpdSssiInterface
{
public String execute(String[] args, HttpRequest httpRequest, HttpdProperties httpdProperties) throws Exception
{
String timeZoneId = "GMT";
if (args.length > 0)
timeZoneId = args[0].trim().toUpperCase();
return ZoneTime.dateToShortString(timeZoneId, false) + " (" + timeZoneId + ")";
}
}
Example Result on Web Browser Window:
Current Time = 20 Aug 2002 00:26:15 (ECT)SSSI directives syntax inside a HTML file:
<!-- @SSSI_CLASS(["ARGUMENT 1" [, "ARGUMENT n"]]) --> Example: <!-- @MySssiClass(55, "this is a \"test\"") any comment --> HTML Result: <!-- @MySssiClass(55, "this is a \"test\"") any comment -->return value from SSSI<!-- [sssi done] -->It is formatted like an HTML comment, so the browser will not display the call of the SSSI - it will display only the result of the java SSSI program. After the SSSI has been executed, additionally the HTML comment <!-- [sssi done] --> will be inserted, that in case of problems you are able to distinguish between the SSSI HTML output and the further static HTML code.
Under some special cases - for example to set a HTML form input value with an SSSI - it is necessary to remove completely any SSSI HTML comment from the final HTML output. Use in such a case a double "@@" instead of one.
Example: <input type="text" name="phone" value="<!-- @@PhoneNumberSssi() -->"> HTML Result: <input type="text" name="phone" value="return value from SSSI">Hint: Only static parameters can be transferred from a HTML file to a SSSI. But inside the SSSI, by using the reference to the HttpRequest, the SSSI has access to all dynamic HTTP request CGI parameters and also to the HTTP POST content (HTML form parameters). This allows generating dynamic SSSI responses.
If a SSSI call fails, you should also have a look of the resulting HTML page. In the most cases you will find the reason in a special HTML comment. However, if the sssi class has not been found, a "500 Internal Server Error" will be displayed (you should check in such a case also the log file of the web server).
Conclusion
SSSI is certainly not a replacement for generating full dynamic web pages with Weblets. But it is a great way to add
small amounts of dynamic content to pages, without doing a lot of extra work. During the execution of a SSSI, you have
full access to the original http request from the browser and to the web server configuration. The result is
an easy and powerful way of programming.
Built-in Security: before execution of a class, the Femto Web Server will check if the class implements the HttpdSssiInterface. This will be done before an instance of the class has been created (to avoid security problems by executing the constructor). If the HttpdSssiInterface is not implemented, the class will not be executed.
Hint 1: make sure that the SSSI is part of the CLASSPATH during execution of the Femto Web Server.
Hint 2: an other way to create dynamic content is also the usage of Weblets.
Httpd,
HttpRequest,
HttpdProperties,
HttpdWebletInterface| Method Summary | |
java.lang.String |
execute(java.lang.String[] args,
HttpRequest httpRequest,
HttpdProperties httpdProperties)
Executes the SSSI. |
| Method Detail |
public java.lang.String execute(java.lang.String[] args,
HttpRequest httpRequest,
HttpdProperties httpdProperties)
throws java.lang.Exception
args - parameters of the SSSI call from the HTML file. If no parameter is given, the array has a length
of zero (but will never be null)httpRequest - access to the HTTP request data (browser request)httpdProperties - read/only access to the Femto Web Server configuration
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||