Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.

JspEncoding

Since: PMD 4.0

Priority: Medium (3)

A missing ‘meta’ tag or page directive will trigger this rule, as well as a non-UTF-8 charset.

This rule is defined by the following XPath expression:

//CompilationUnit/Content[
not(Element[@Name="meta"][
   Attribute[@Name="content"]/AttributeValue[contains(lower-case(@Image),"charset=utf-8")]
])
and
    not(JspDirective[@Name='page']/JspDirectiveAttribute[@Name='contentType'][contains(lower-case(@Value),"charset=utf-8")])
]

Example(s):

Most browsers should be able to interpret the following headers:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" />

Use this rule by referencing it:

<rule ref="category/jsp/errorprone.xml/JspEncoding" />