##### Overview

- Download PMD 3.7
- What's new in PMD 3.7
- PMD in the news
- PMD-related products and books
- Best practices
- Future directions
- Similar projects
- Credits
- License
- What does 'PMD' mean?

##### Usage

- Installation
- Command line usage
- Ant task usage
- Maven plugin usage
- IDE plugin usage
- Suppressing warnings
- Finding duplicated code
- JSP support

##### Customizing PMD

- Compiling PMD
- How to write a rule
- Writing XPath rules
- How to make a rule set
- How it works

##### For example

- Run PMD on a Sourceforge project

##### Rule Sets

- Index
- Basic
- Braces
- Code Size
- Clone
- Controversial
- Coupling
- Design
- Finalizers
- Import Statements
- J2EE
- Javabeans
- JUnit Tests
- Logging (Java)
- Logging (Jakarta)
- Migrating
- Naming
- Optimizations
- Strict Exceptions
- Strings
- Sun Security
- Unused Code
- Java Server Pages
- Java Server Faces

##### Project Documentation

- About PMD
- Project Info
- Project Reports
- Development Process

## Basic JSP rules

Rules concerning basic JSP guidelines.

### NoLongScripts

Scripts should be part of Tag Libraries, rather than part of JSP pages.

This rule is defined by the following XPath expression:

    // Element [ string:upper-case(@Name)="SCRIPT" and (@EndLine - @BeginLine &gt; 10) ]

Here's an example of code that would trigger this rule:

    &lt;HTML&gt;
    &lt;BODY&gt;
    &lt;!--Java Script--&gt;
    &lt;SCRIPT language="JavaScript" type="text/javascript"&gt;
    &lt;!--
    function calcDays(){
      var date1 = document.getElementById('d1').lastChild.data;
      var date2 = document.getElementById('d2').lastChild.data;
      date1 = date1.split("-");
      date2 = date2.split("-");
      var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
      var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
      var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));
      document.getElementById('diffDays').lastChild.data = daysApart;
    }

    onload=calcDays;
    //--&gt;
    &lt;/SCRIPT&gt;
    &lt;/BODY&gt;
    &lt;/HTML&gt;

### NoScriptlets

Scriptlets should be factored into Tag Libraries or JSP declarations, rather than being part of JSP pages.

This rule is defined by the following XPath expression:

    					 //descendant::*[
    self::JspScriptlet  or (self::Element and string:upper-case(@Name)="JSP:SCRIPTLET") ]

Here's an example of code that would trigger this rule:

    &lt;HTML&gt;
    &lt;HEAD&gt;
    &lt;%
    response.setHeader("Pragma", "No-cache");
    %&gt;
    &lt;/HEAD&gt;
    	&lt;BODY&gt;
    		&lt;jsp:scriptlet&gt;String title = "Hello world!";&lt;/jsp:scriptlet&gt;
    	&lt;/BODY&gt;
    &lt;/HTML&gt;

### NoInlineStyleInformation

Style information should be put in CSS files, not in JSPs. Therefore, don't use <B> or <FONT> tags, or attributes like "align='center'"

This rule is defined by the following Java class: net.sourceforge.pmd.jsp.rules.NoInlineStyleInformation

Here's an example of code that would trigger this rule:

    &lt;html&gt;&lt;body&gt;&lt;p align='center'&gt;&lt;b&gt;text&lt;/b&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;

### NoClassAttribute

Do not use an attribute called 'class'. Use "styleclass" for CSS styles.

This rule is defined by the following XPath expression:

    					 //Attribute[ string:upper-case(@Name)="CLASS" ]

Here's an example of code that would trigger this rule:

    &lt;HTML&gt; &lt;BODY&gt;
    &lt;P class="MajorHeading"&gt;Some text&lt;/P&gt;
    &lt;/BODY&gt; &lt;/HTML&gt;

### NoJspForward

Do not do a forward from within a JSP file.

This rule is defined by the following XPath expression:

    					 //Element[ @Name="jsp:forward" ]

Here's an example of code that would trigger this rule:

    &lt;jsp:forward page='UnderConstruction.jsp'/&gt;

### IframeMissingSrcAttribute

IFrames which are missing a src element can cause security information popups in IE if you are accessing the page through SSL. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q261188

This rule is defined by the following XPath expression:

    	//Element[string:upper-case(@Name)="IFRAME"][count(Attribute[string:upper-case(@Name)="SRC" ]) = 0]

Here's an example of code that would trigger this rule:

    &lt;HTML&gt;&lt;title&gt;bad example&gt;&lt;BODY&gt;
    &lt;iframe&gt;&lt;/iframe&gt;
    &lt;/BODY&gt; &lt;/HTML&gt;

    &lt;HTML&gt;&lt;title&gt;good example&gt;&lt;BODY&gt;
    &lt;iframe src="foo"&gt;&lt;/iframe&gt;
    &lt;/BODY&gt; &lt;/HTML&gt;

### NoHtmlComments

In a production system, HTML comments increase the payload between the application server to the client, and serve little other purpose. Consider switching to JSP comments.

This rule is defined by the following XPath expression:

    	//CommentTag

Here's an example of code that would trigger this rule:

    &lt;HTML&gt;&lt;title&gt;bad example&gt;&lt;BODY&gt;
    &lt;!-- HTML comment --&gt;
    &lt;/BODY&gt; &lt;/HTML&gt;

    &lt;HTML&gt;&lt;title&gt;good example&gt;&lt;BODY&gt;
    &lt;%-- JSP comment --%&gt;
    &lt;/BODY&gt; &lt;/HTML&gt;

### DuplicateJspImports

Avoid duplicate import statements inside JSP's.

This rule is defined by the following Java class: net.sourceforge.pmd.jsp.rules.DuplicateJspImports

Here's an example of code that would trigger this rule:

    &lt;%@ page import=\"com.foo.MyClass,com.foo.MyClass\"%&gt;&lt;html&gt;&lt;body&gt;&lt;b&gt;&lt;img src=\"&lt;%=Some.get()%&gt;/foo\"&gt;xx&lt;/img&gt;text&lt;/b&gt;&lt;/body&gt;&lt;/html&gt;