Installation Guide

This package comes with pre-built binaries located in the dist directory. Those distribution files are:

filedescription
jtidyservlet.jarthe taglib and servlet jar
jtidy-taglib-12.tldthe taglib tld file
jtidyservlet-webapp.wardocumentation and examples

To quickly view the documentation and examples showing the features and functionality of the JTidy servlet lib, just deploy the jtidyservlet-webapp.war file to your application server (the details of how differ from server to server). You could see this deployment here Live examples

If you would like to make use of the JTidy servlet lib in your own application, do the following:

STEP 1: Drop the jtidyservlet-{version}.jar file in your application WEB-INF/lib directory

STEP 2: Make sure that following libraries are in your WEB-INF/lib directory (or made available via the classpath to your application server). Refer to the runtime dependencies document for the correct version of these libraries. You can download a copy of everything from jakarta or you can grab them from the example webapp in the bin distribution.

  • commons-logging.jar
  • jtidy-r8.jar
  • xerces.jar
  • xml-apis.jar

STEP 3: Optional Configure new JTidyServlet in your web.xml. You need this to see the JTidy reports/(processing results and icons) in your web application. See STEP 5 - Security considerations before you make this changes on production system.

<servlet>
    <servlet-name>JTidyServlet</servlet-name>
    <servlet-class>org.w3c.tidy.servlet.TidyServlet</servlet-class>
</servlet>
                
<servlet-mapping>
    <servlet-name>JTidyServlet</servlet-name>
    <url-pattern>/JTidy</url-pattern>
</servlet-mapping>
                

STEP 4: Select OPTION A if you will use tags or OPTION B if you will use Filter. It is also possible to use Filter and tags at the same time

OPTION A

If you are going to use tags for syntax checking and/or cleaning up generated HTML.

STEP A.1: Needed only for jsp 1.1 containers. Drop the jtidyservlet-{taglibversion}.tld file in your application WEB-INF/ directory. Refers to the tlds page for the available tlds.

STEP A.2: Needed only for jsp 1.1 containers. Define a taglib element like the following in your /WEB-INF/web.xml file

<taglib>
    <taglib-uri>http://jtidy.sf.net</taglib-uri>
    <taglib-location>/WEB-INF/jtidy-taglib-{taglibversion}.tld</taglib-location>
</taglib>
                

STEP A.3: Define the tag extension in each JSP page that uses the jtidy taglib or in commonly included JSP. The uri directives must match what you defined in the web.xml file above OR the URI defined in one of the tlds in the jar file. With jsp 1.2 containers the jar file is automatically scanned and you don't need to define any entry in your web.xml file. The prefix identifies the tags in the tag library within the JSP page.

<%@ taglib uri="http://jtidy.sf.net" prefix="jtidy" %>

The declaration, if you are using a jsp xml sintax, looks like:

<jsp:root version="1.2" xmlns:jsp="http://java.sun.com/JSP/Page"
     xmlns:jtidy="urn:jsptld:http://jtidy.sf.net">
                    

Surround your complete html generation code with <jtidy:tidy> tag

<jtidy:tidy>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
  <title>My Page</title>
</head>
<body>
</body>
    My page body
    <%
        // Do anything
    %>
</html>
</jtidy:tidy>
                     

OPTION B

If you are going to use Filter for syntax checking and/or cleaning up generated or static HTML. This way you don't need to modify your JSP files.

STEP B.1: Configure the JTidyFilter in your web.xml:

<filter>
    <filter-name>JTidyFilter</filter-name>
    <filter-class>org.w3c.tidy.servlet.filter.JTidyFilter</filter-class>
</filter>
                    

And add mappings for the pages that you will intercept, for example:

<filter-mapping>
    <filter-name>JTidyFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>JTidyFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>
                    

DONE: During development you may include

<jtidy:validationImage/>

inside common header JSP(Tile) to see immediately if the page you are manually testing is well formatted.

ImageDescription
Page Validation OKNo problems
Page Validation WarningSome problems
Page Validation ErrorSerious errors
Page Validation OffJTidy did not processed this request

Also see examples there are many ways to do this. See Configuration for more details on how you could customize JTidyServelt for your application.

For more help with using taglibs in general, please see: http://jakarta.apache.org/taglibs/tutorial.html

STEP 5: Security considerations

Default results Repository stores all generated HTML pages in memory and these pages are accessible to application end user via JTidyServlet. DefaultRepositoryFactory returns only one global instance of Repository. This may be convenient during application development but is not aceptable for production system.

For production you definitely need to disable HTML pages storage and use SessionRepositoryFactory. Example file JTidyServletProduction.properties is included in jtidyservlet.jar. As to me I'm not using JTidyServlet in production deployment because by the time of production I already fixed :) all errors in my application.