Wednesday, January 18, 2006

JSP 2.0 Useful trick

It isn't anything new but people (including myself) often forget about some of the useful features of JSP 2.0 that is by the way supported by the whole family Tomcat 5.*

The tag JSP <jsp-property-group> is very handy, the example below defines a page group on which it applies the following properties:
  • define the charset
  • disable scripting
  • ignore expressions like ${param.name}
  • include JSP fragments (top and bottom)
<jsp-config>
<jsp-property-group>
<description>
Property group for custom JSP Configuration.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>/view/*</url-pattern>
<page-encoding>ISO-8859-1</page-encoding>
<scripting-invalid>true</scripting-invalid>
<el-ignored>true</el-ignored>
<include-prelude>/common/top.jspf</include-prelude>
<include-coda>/common/bottom.jspf</include-coda>
</jsp-property-group>
</jsp-config>
The proper schema needs to be specified in the deployment descriptor:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

0 Comments:

Post a Comment

<< Home