Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.
The following example shows the syntax:
< % @ include file="copyright.html" % >
Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.
How do I have the JSP-generated servlet subclass my own custom servlet class, instead of the default? One should be very careful when having JSP pages extend custom servlet classes as opposed to the default one generated by the JSP engine.
In doing so, you may lose out on any advanced optimization that may be provided by the JSPengine.
In any case, your new super class has to fulfill the contract with the JSP engine by:
Implementing the HttpJspPage interface, if the protocol used is HTTP, or implementing JspPage otherwise Ensuring that all the methods in the Servlet interface are declared final. Additionally, your servlet super class also needs to do the following:
The service() method has to invoke the _jspService() method The init() method has to invoke the jspInit() method The destroy() method has to invoke jspDestroy() If any of the above conditions are not satisfied, the JSP engine may throw a translation error.
Once the super class has been developed, you can have your JSP extend it as follows:
No comments:
Post a Comment