Middle
How is JSP configured in the deployment descriptor?
sobes.tech AI
Answer from AI
JSP configuration in the deployment descriptor (web.xml) allows managing their behavior and settings.
Main elements used for JSP configuration:
<jsp-config>: Root element for JSP configuration.<taglib>: Tag library configuration.<taglib-uri>: URI used in thetaglibdirective in JSP.<taglib-location>: Path to the TLD file (Tag Library Descriptor).
<jsp-property-group>: Group of properties applied to a set of JSP pages.<url-pattern>: URL pattern to which properties are applied.<el-ignored>: Specifies whether to ignore EL expressions (defaultfalse).<page-encoding>: Page encoding.<scripting-invalid>: Prohibits the use of scripting elements (<%, %!, %=).<include-prelude>: Path to a file included at the beginning of each JSP.<include-coda>: Path to a file included at the end of each JSP.<default-content-type>: Default content type.<buffer>: Output buffer size.<error-on-undeclared-namespace>: Generate an error when using an undeclared tag prefix.
Configuration example:
<!-- web.xml -->
<web-app ...>
<jsp-config>
<taglib>
<taglib-uri>/mytags</taglib-uri>
<taglib-location>/WEB-INF/mytags.tld</taglib-location>
</taglib>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>true</scripting-invalid>
<include-prelude>/WEB-INF/jspf/header.jspf</include-prelude>
<include-coda>/WEB-INF/jspf/footer.jspf</include-coda>
</jsp-property-group>
<jsp-property-group>
<url-pattern>/admin/*.jsp</url-pattern>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
</jsp-config>
</web-app>
This configuration:
- Associates the URI
/mytagswith the file/WEB-INF/mytags.tldfor tag libraries. - Applies the following properties to all JSPs (
*.jsp):- EL is not ignored.
- UTF-8 encoding.
- Scripting is disabled.
/WEB-INF/jspf/header.jspfis included before the JSP content./WEB-INF/jspf/footer.jspfis included after the JSP content.
- For JSPs in the
/admin/directory, scripting is enabled, overriding the general setting.
Using <jsp-property-group> allows flexible configuration of JSP behavior depending on their location or filename pattern.